admin管理员组

文章数量:1402059

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.

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.

Share Improve this question asked Nov 5, 2008 at 16:46 Brian LiangBrian Liang 7,77410 gold badges60 silver badges72 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

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

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

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 Javascript it renders and use that in your function to trigger the correct server-side event.

Below is one way to notify the server of an event. You are really firing a client side event but then municating 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
        }
    }

}

本文标签: netHow do you raise a serverside event from javascriptStack Overflow