Ajax-based: examples of real-time data refreshing, real-time display status, and partial refreshing.

Source: Internet
Author: User
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 ();
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.