asp:AsyncPostBackTrigger post-backing on fire.

1.8k Views Asked by At

I am using AJAX.NET's update panels in the below manner. My code works perfect with .NET framework 4.0 but for some strange reasons I have to use this application in .NET framework 2.0 When I tried to run the below code in ASP.NET 2.0 on every button click page is post backing which I don't want. Can anybody tell me why page reloading even I used asp:AsyncPostBackTrigger

Code follows.

Default.aspx

<%@ 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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
        </Triggers>
        <ContentTemplate>
            <asp:Label ID="Label1" runat="server"></asp:Label>
            <asp:Button ID="Button1" runat="server" Text="update" onclick="Button1_Click" />
        </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>

Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = Convert.ToString(DateTime.Now);
    }
}

Web.config

<configuration>
  <system.web>
    <compilation debug="true">
      <assemblies>
        <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </assemblies>
    </compilation>

    <customErrors mode="Off"/>
    <pages>
      <controls>
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </controls>
    </pages>
  </system.web>
</configuration>
2

There are 2 best solutions below

2
On BEST ANSWER

Your code is correct and runs fine even under ASP.NET 2.0. As every asynchronous postback actually does make a post back to the page, I assume you meant that clicking on Button1 in your installation makes the page completely refresh (instead of just refreshing partially). If this is the case, I think this issue may be related to a missing entry in your web.config, that prevents the client portion of ASP.NET Ajax to handle the partial postbacks correctly. Here is what you should add (excerpt):

<httpHandlers>
  <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
2
On

I found the answer. Just change your application pool from DefaultAppPool to ClassicAppPool. Doing this everything should work fine.