Code Snip "AJAX Timer"
Tired of receiving the same email, this is the code for the timer. Normal mistake, people sets the timer outside the UpdatePanel
<
html xmlns="http://www.w3.org/1999/xhtml" ><
head runat="server"><title>Untitled Page</title>
</
head><
body><form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</
body></
html>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
Label1.Text =
"Timer will run every 5 seconds to display the time in an Update Panel";}
protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text =
DateTime.Now.ToString();}



Comments
TrackBack said on 12.22.2006 at 2:42 PM
DotNetKicks.com said on 12.22.2006 at 9:52 PM
You've been kicked (a good thing) - Trackback from DotNetKicks.com
ujjwal b soni said on 9.15.2008 at 2:57 AM
Hi,
The article is very nice !!!
Regards,
Ujjwal B Soni