Click "Start Timer" when ready.
The AsyncTimer is a simple Async-Enabled timer server control.
<%@ Register Assembly="AsyncControls" Namespace="DelvingWare.AsyncControls" TagPrefix="dw" %> <%@ Register Assembly="AsyncControls" Namespace="DelvingWare.AsyncControls.Utils" TagPrefix="dw" %> <dw:AsyncTimer runat="server" ID="tmrMain" Interval="1000" OnTick="tmrMain_Tick" /> <p> <dw:AsyncButton runat="server" ID="btStart" Text="Start Timer" CausesValidation="true" OnClick="btStart_Click" DisableDuringCallback="false" CssClass="greyButton"/> <dw:AsyncButton runat="server" ID="btStop" Enabled="false" Text="Stop Timer" OnClick="btStop_Click" DisableDuringCallback="false" CssClass="greyButton"/> </p> Interval: <dw:AsyncTextBox runat="server" ID="txtInterval" Size="3" MaxLength="4" EnableValidation="enabled" MultiValidate="Range|RequiredField" ErrorMessageCssClass="errorMsg" ErrorMessage="Please enter a valid timer interval. 1000 - 5000 " MinimumValue="1000" MaximumValue="5000" Text="1000" />(ms) <br/> <dw:AsyncLinkButton runat="server" ID="lnkMain" OnClick="lnkMain_Click" CausesValidation="true" Visible="false" Text="Update Tick Interval" /> <dw:AsyncLabel runat="server" ID="lblMain" RenderMode="paragraph">Click "Start Timer" when ready.</dw:AsyncLabel>
using System; using DelvingWare.AsyncControls; ... protected void Page_Load( object sender, EventArgs e ) { // enable AsyncWindow use AsyncPage.Invocation.EnableAsyncTimer = true; } protected void tmrMain_Tick( object sender ) { // update the AsyncLabel text lblMain.Text = "The current server time is: "+ DateTime.Now; } protected void btStop_Click( object sender, AsyncEventArgs ae ) { // enable, disable the AsyncButtons btStart.Enabled = true; btStop.Enabled = false; // hide the AsyncLinkButton lnkMain.Visible = false; // stop the AsyncTimer tmrMain.Stop(); // update the AsyncLabel text lblMain.Text = "Click \"Start Timer\" when ready."; // select all the text within the AsyncTextBox txtInterval.SelectAll(); // set the user input focus the the AsyncTextBox txtInterval.Focus(); } protected void btStart_Click( object sender, AsyncEventArgs ae ) { // ensure the page passed validation if ( !AsyncPage.IsValid ) return; // disable/enable the AsyncButtons btStart.Enabled = false; btStop.Enabled = true; // show the AsyncLinkButton lnkMain.Visible = true; // set the AsyncTimer tick interval based on the user input tmrMain.Interval = int.Parse(txtInterval.Text); // start the timer tmrMain.Start(); // update the AsyncLabel text lblMain.Text = "Click \"Stop Timer\" when ready."; } protected void lnkMain_Click( object sender, AsyncEventArgs ae ) { if ( !txtInterval.IsValid ) return; // update the AsyncLabel lblMain.Text = "Updated the tick interval to "+ txtInterval.Text +" (ms)."; // update the interval tmrMain.Interval = int.Parse(txtInterval.Text); }
Imports System Imports DelvingWare.AsyncControls ... Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) ' enable AsyncWindow use AsyncPage.Invocation.EnableAsyncTimer = true End Sub Protected Sub tmrMain_Tick(ByVal sender As Object) ' update the AsyncLabel text lblMain.Text = ("The current server time is: " + DateTime.Now) End Sub Protected Sub btStop_Click(ByVal sender As Object, ByVal ae As AsyncEventArgs) ' enable, disable the AsyncButtons btStart.Enabled = true btStop.Enabled = false ' hide the AsyncLinkButton lnkMain.Visible = false ' stop the AsyncTimer tmrMain.Stop ' update the AsyncLabel text lblMain.Text = "Click \""Start Timer\"" when ready." ' select all the text within the AsyncTextBox txtInterval.SelectAll ' set the user input focus the the AsyncTextBox txtInterval.Focus End Sub Protected Sub btStart_Click(ByVal sender As Object, ByVal ae As AsyncEventArgs) ' ensure the page passed validation If Not AsyncPage.IsValid Then Return End If ' disable/enable the AsyncButtons btStart.Enabled = false btStop.Enabled = true ' show the AsyncLinkButton lnkMain.Visible = true ' set the AsyncTimer tick interval based on the user input tmrMain.Interval = Integer.Parse(txtInterval.Text) ' start the timer tmrMain.Start ' update the AsyncLabel text lblMain.Text = "Click \""Stop Timer\"" when ready." End Sub Protected Sub lnkMain_Click(ByVal sender As Object, ByVal ae As AsyncEventArgs) If Not txtInterval.IsValid Then Return End If ' update the AsyncLabel lblMain.Text = ("Updated the tick interval to " _ + (txtInterval.Text + " (ms).")) ' update the interval tmrMain.Interval = Integer.Parse(txtInterval.Text) End Sub