Refreshing Update Panel Igot a problem if the user is writing at that time
Im trying to make a web chat using ajax control tool kit. There is a script mannager, the update panel and the timer.
I inserted the textbox for showing every text that is introduced by the users, the text for writing and th开发者_高级运维e send button are out. It works great but if im writing some text in the exact moment of refreshing time (winch happends a lot because its every 3 sec) it does not let me write correctly cause the textbox kind of blink and you miss a letter. So, wich is the correct method for doing this without lossing the fluidity of the writing.
Thanks.
I would suggest you to create 2 textboxes: one for input and anther for output. The one for input should be placed outside the update panel, so it never will be refreshed. Also you will need to add this textbox or its send button as a trigger to your update panel. Similar to this example
Here is the code I tried and it works:
Aspx:
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="2000" Enabled="True">
</asp:Timer>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" Text="Submit" runat="server" OnClick="Button1_Clicked" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="" />
</ContentTemplate>
</asp:UpdatePanel>
And C#:
protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}
protected void Button1_Clicked(object sender, EventArgs e)
{
Label1.Text = String.Format("{0}: {1}", DateTime.Now.ToString(), TextBox1.Text);
}
精彩评论