views:

207

answers:

2

So i'm implementing a feature where after a user has visited my site, and not signed in and not registered for over two minutes, an alert pops up and asks them to take a survey.

I agree, annoying, but it's a business requirement.

I thought about doing a Session Object, and then in the page_load of the header (since it's on every page) check if the current time is greater than the time in session.

However, this will only fire when the page loads. I kind of need it to pop up at exactly tw minutes.

So I looked into the ASP.NET AJAX timer, which seems to do the trick.

My question is how do you disable it? Because now it just keeps firing every 20 seconds which is what my current interval is.

I thought about maybe setting a cookie and if the cookie isn't present show it, otherwise don't.

Just wondering if anyone else had any insight into this.

Thanks guys!

A: 

You can use the JavaScript windows.setTimeOut method which will fire exactly once after whatever time is specified.

window.setTimeOut(foo,2000);

The above will call the foo JavaScript function after 2 seconds.

Thanks,

azamsharp
Just a note: the O should be lower-case: setTimeout()
M4N
A: 

The problem with the setTimeout() approach as shown by azamsharp is that it only works if the user stays on the same page during the two minutes.

If you have different pages, the you will probably have to implement a solution involving the asp.net session and client-side scripting, e.g:

  • store a DateTime in the session when the alert must be shown
  • (on every page) call a page-method from javascript (e.g. every 5 seconds) to check if the alert is due, and show it if it is due
  • put the javascript part (the call of the pagemethod) into a common master page and use this for each asp.net page
M4N
Only problem I see with session is that if the user comes back to the site tomorrow, they'll get hit with the same annoying pop up. I think I'm going to set a cookie. At least if they come back on the same computer they won't get bothered.
Jack Marchetti
Yes I guess a cookie would be even better than using session
M4N