Aspx page:
_ Default is the class name, And GetServiceStatus is a method in the class.
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> Untitled Page </title>
<Script language = Javascript>
Function SetMessage ()
{
_ Default. GetServiceStatus (GetMessage_CallBack );
}
Function GetMessage_CallBack (response)
{
Var btn = document. getElementById ('<% = btnSet. ClientID %> ');
Var btnPanel = document. getElementById ('btnpanel ');
Var lbl = document. getElementById ('lblstatus ');
Var status = response. value;
Switch (status)
{
Case "Running ":
Lbl. innerText = "running ";
Btn. value = "stop ";
BtnPanel. style. visibility = "visible ";
Break;
Case "Stopped ":
Lbl. innerText = "STOPPED ";
Btn. value = "start ";
BtnPanel. style. visibility = "visible ";
Break;
Case "StartPending ":
Lbl. innerText = "starting ";
BtnPanel. style. visibility = "hidden ";
Break;
Case "StopPending ":
Lbl. innerText = "Stopping ";
BtnPanel. style. visibility = "hidden ";
Break;
}
}
</Script>
</Head>
<Body onload = "setInterval ('setmessage', 100);">
<Form id = "form1" runat = "server">
<Table>
<Tr> <td width = "250"> <div id = "lblStatus"> </div> </td> <td>
<Div id = "btnPanel" style = "visibility: visible"> <asp: button ID = "btnSet" runat = "server" Text = "Button" OnClick = "btnSet_Click1"/> </div> </td> </tr>
</Table>
</Form>
</Body>
</Html>
. Cs File
Protected void Page_Load (object sender, EventArgs e)
{
Ajax. Utility. RegisterTypeForAjax (typeof (_ Default ));
}
[Ajax. AjaxMethod ()]
Public string GetServiceStatus ()
{
Return ctl. Status. ToString ();
}