views:

1871

answers:

4

I have a control that is basically functioning as a client-side timer countdown control.

I want to fire a server-side event when the count down has reached a certain time.

Does anyone have an idea how this could be done?

So, when timer counts down to 0, a server-side event is fired.

+1  A: 

When you render the page create a client-side button that would do the action you want on postback. Then use ClientScriptManager.GetPostBackEventReference passing in the control as reference and add a client-side event to it using attributes as the example at the bottom of that link shows.

You can then see the javscript it renders and use that in your function to triger the correct server-side event.

Dave Anderson
+3  A: 

You would probably want to use AJAX to make your server side call.

CubanX
+2  A: 

IIRC, there is a timer server control that should do this for you.

Joel Coehoorn
+2  A: 

Below is one way to notify the server of an event. You are really firing a client side event but then communicating with the server. This is if you aren't living in an AJAX world though.

function NotifyServer()
{
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlHttp.onreadystatechange = OnNotifyServerComplete;
    xmlHttp.open("GET", "serverpage.aspx", true);
    xmlHttp.send();
}
function OnNotifyServerComplete()
{
    if (xmlHttp.readyState == 4)
    {
     if (xmlHttp.status == 200)
     {
      if (xmlHttp.responseText != "1")
       //do something
     }
    }

}
wonderchook