How to create Server Side timer control in asp.net
Step 1: Create your web application first and then create one .aspx page .Step 2: Open your .aspx page and add Timer Control by Drag and Drop from Toolbox dialog box
Step 3: Also add Script Manager to the page to run timer control.
Step 4: Add one Event to timer control is ontick also set Interval="1000" time 1000 =1 sec
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
</asp:Timer>
Step 5: Also one Label Control to page to display timer changes
Step 6: Put below code on page
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="lblTimer" runat="server" Text="Label"></asp:Label>
Step 7:Add onTick code at server side.
protected void Timer1_Tick(object sender, EventArgs e)
{
lblTimer.Text = DateTime.Now.ToString();
}
Step 8 : To start timer active the timer property Enable = true
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Timer1.Enabled = true;
}
}
Step 10: This way you can access timer control.
nice... you can try this also...
ReplyDeletehttp://www.alltechmantra.com/2013/12/how-to-use-timer-control-in-asp.html