Normal
0
false
false
false
EN-US
X-NONE
X-NONE
MicrosoftInternetExplorer4
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:"Times New Roman";
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
By using PageMethods you can minimize the traffic going
over the wire – check this out. (UpdatePanel is extremely chatty, and has some performance considerations).
UpdateTime gets the current time by calling a WebMethod and
specifying the two callbacks (OnSucceeded and OnFailed).
<asp:ScriptManager ID="ScriptManager1"
runat="server"
EnablePageMethods="true"
/>
<script language="javascript">
function UpdateTime() {
PageMethods.GetCurrentDate(OnSucceeded, OnFailed);
}
function OnSucceeded(result, userContext,
methodName) {
$get('Label1').innerHTML = result;
}
function OnFailed(error, userContext,
methodName) {
$get('Label1').innerHTML = "An error occured.";
}
</script>
<asp:Label runat="server"
ID="Label1"
Text="Update
Me!" /><br />
<input type="button"
id="Button2"
value="Web Method
Update"
onclick="UpdateTime();"
/>
Here’s the server-side webmethod:
[WebMethod]
public static string GetCurrentTime()
{
return DateTime.Now.ToLongTimeString();
}
There is no post-data, and the response looks as follows (JSON):
{"d":"05:21:24
PM"}
Does this help?