views:

190

answers:

6

how to display something one time every hour in asp.net ?

example for show messeage in Begining hour one time only?

i use for asp.net ajax timer control?


protected void Timer1_Tick(object sender, EventArgs e)
{
    MessageBoxShow(Session["playsound"].ToString());
    Session["playsound"] = 1;
}

but alway null?

---------------------------
Message from webpage
---------------------------
Object reference not set to an instance of an object.
---------------------------
OK   
---------------------------
A: 

On the client?

The only way I know to do this is via a javascript timer.

Sir Psycho
yes On the client, but can i use for asp.net ajax timer control?
monkey_boys
A: 

You can use the

window.setInterval

method

It calls a function repeatedly, with a fixed time delay between each call to that function.

intervalID = window.setInterval(func, delay[, param1, param2, ...]);

Read more info

window.setInterval

rahul
A: 

One way of doing this could be to have an session variable with NextTime to show the item on the page. If its null one could display the item now (or get the NextTime scheduled). On every page refresh, if the current time is after the Next Time, show the item and reset the NextTime session variable to the next Hour.

This would only work if the user is navigating the site and the page is being refreshed.

Mark Redman
protected void Timer1_Tick(object sender, EventArgs e) { MessageBoxShow(Session["playsound"]); Session["playsound"] = 1;}but alway null?
monkey_boys
There is no need for a timer. you would do the check to play the sound on every page load.
Mark Redman
I dont get the -1? please explain?
Mark Redman
Sesstion Not work i try for used QueryString and Javascript
monkey_boys
A: 

You can use the javascript variable window.name which keeps its value between page refreshes.

You could store a 'last checked time' in there and compare it with the current time.

If the user navigates to another site and that site clears this variable then your back to square one.

Sir Psycho
+1  A: 

Sounds like your session might have timed out. If, between AJAX calls, your session expires on the server, then the ToString invocation may be operating on a null reference:

MessageBoxShow(Session["playsound"].ToString());

This would appear to coincide with what the AJAX client script is attempting to tell you.

This could also be the result of Session["playsound"]; being uninitialised.

The default session expiry duration for ASP.NET is 20 minutes, which you should be mindful of if you're executing an hour long timer.

Rabid
A: 

An easy answer would be to use a small cookie to store the original time and then query it every so often (~5 min?) this way the session won't run out and you're not SOL if the user leaves the page (if that's what you want).

DISCLAIMER: I haven't really dipped my toes into AJAX yet even though I've been programming ASP.net all summer, so excuse me if this isn't possible.

CodePartizan