ASP.NET AJAX UpdatePanels post less data by JSON

OLD style:

<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" ID="up1">
<asp:Label runat="server" ID="Label1" Text="Update Me!" /><br />
<asp:Button runat="server" ID="Button1"
Text="Postback Update" OnClick="Button1_Click" />

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.";
<asp:Label runat="server" ID="Label1" Text="Update Me!" /><br />
<input type="button" id="Button2" value="Web Method Update"
onclick="UpdateTime();" />

public static string GetCurrentDate()
return DateTime.Now.ToLongDateString();


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s