Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting asp.net timer interval programmatically

I am developing an asp.net website. I have an asp:Timer control to update the page for every 10 minutes. I did that setting the interval property as shown below..

<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="100000" Enabled="True"></asp:Timer>

Now I have a requirement where I need the user to select the interval period on the screen and based on what the user selects, the 'Interval' value should change.

So the user has something like this on the screen:

 10 min   15 min 20 min

Clicking on any of the above time interval values, the 'Interval' value should change.

I searched online and don't seem to get any idea on how I can go forward. How can I get this done?

like image 266
CodeNinja Avatar asked Dec 03 '25 18:12

CodeNinja


1 Answers

The solutions seem to be simple using ASP.NET Ajax Timer:

  1. Don't use the hard-coded value in HTML (that portion Interval="100000" pointed out in previous comments). Instead, put the timer initialization in Page_Load event (!IsPostBack){ }

  2. On every Timer.Tick event check for the content of that drop-down (or whatever control you provide to User for changing the interval) and change the interval if necessary.

    2a. If you re-load the page, then you can persist the interval value either in the cookies, or session variable.

like image 91
Alexander Bell Avatar answered Dec 06 '25 08:12

Alexander Bell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!