I have an ASP.NET web site. I want a user to make a decision and click one of the given buttons within a certain amount of time and redirect him to another page. If he didn’t make a decision, he still will be redirected with “no choice made” mark in my head.
I use asp:Timer to initiate postback after time is up. I’m doing redirect by calling Response.Redirect('page.html', false) in Page_Load handler. In this case I can handle button_click or timer_tick events before actually redirecting. After one of those events is processed, page is rendered and redirect is done.
But I have two problems. First, if input is processed long enough, second timer’s tick is triggered, new postback initiated, and my current is canceled! Second, if user click a button just before the time is up, the timer tick occurs before redirect is done and it again overrides handling of user click!
How can I resolve these issues? How can I disable timer on client side after the first tick is triggered or after a user have clicked a button? Or what is the better way of solving my task? Thanks.
I got the solution for both problems.
I placed
asp:Timerinside anasp:UpdatePanelcontrol. This is the right thing to do in my case since I don’t need to refresh entire page before the next question. But I discovered that in this case ticks from timer don’t interfere with each other.As described here, I can disable
asp:Timerusing javascript like this:Then I bind this to my buttons’
onclickevent and I’m done. Since timer is placed inside anUpdatePanel, it is autmatically recreated and enabled after a postback.