OLD style:
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" ID="up1">
<ContentTemplate>
<asp:Label runat="server" ID="Label1" Text="Update Me!" /><br />
<asp:Button runat="server" ID="Button1"
Text="Postback Update" OnClick="Button1_Click" />
ContentTemplate>
asp:UpdatePanel>
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToLongDateString();
}
NEW style:
<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();" />
[WebMethod]
public static string GetCurrentDate()
{
return DateTime.Now.ToLongDateString();
}
No comments:
Post a Comment