Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.18/5 (3 votes)
See more:
how to use timer in asp.net?
C#

Posted
Updated 10-Jun-18 23:48pm

hi, by adding timer in the page it scrolls the page automatically even if updatepanel is used. so, to overcome this issue I am using following code in page definition

MaintainScrollPositionOnPostback="true"
 
Share this answer
 
<asp:timer id="t1" runat="server" ontick="Timer1_Tick" interval="1000" xmlns:asp="#unknown">


protected Timer1_Tick()
{
int i=0;
t1.Enabled=true;
Button1.Width=Button1.Width-20;
if(i==35)
{
t1.Enabled=false;
}
}
 
Share this answer
 
Comments
kashifjaat 28-Sep-14 23:39pm    
How Set unique timer of every client on page_Load , when page load timer will be start zero, but in my case its not happing , lets if one person is currently use page and i open same page then timer shows the value of that person or page count down??? How I resolve this issu???
Hi ,
This Example will Guide you .
ASP.NET
<div>
     <asp:ScriptManager ID="ScriptManager1" runat="server">
     </asp:ScriptManager>
     <asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval="2000">
     </asp:Timer>
     <asp:UpdatePanel ID="UpdatePanel1" runat="server">
           <ContentTemplate>
               <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
           </ContentTemplate>
               <Triggers>

                   <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />

               </Triggers>
     </asp:UpdatePanel>
 </div>


C#
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Timer1_Tick(object sender, EventArgs e)
{
    Label1.Text = DateTime.Now.ToString();
}

Best Regards
M.Mitwalli
 
Share this answer
 
Comments
Pugal Kannan 2-Jun-14 1:06am    
Above code is working well in local system., but after hosting my website its not working in server
Member 11818688 9-Feb-17 7:28am    
how can stop this timer??????
OK, With reference to this question this is the best source code to be referred, Download it and see how timer works in Online Exams...

Online Exam in C# ASP NET[^]

All The Best:-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900