【问题标题】:asp:AsyncPostBackTrigger post-backing on fire.asp:AsyncPostBackTrigger post-backing on fire。
【发布时间】:2011-10-19 22:20:21
【问题描述】:

我正在以下列方式使用 AJAX.NET 的更新面板。我的代码与 .NET 框架 4.0 完美配合,但由于某些奇怪的原因,我必须在 .NET 框架 2.0 中使用此应用程序当我尝试在每个按钮单击页面上在 ASP.NET 2.0 中运行以下代码时,我不这样做不想要。谁能告诉我为什么即使我使用了asp:AsyncPostBackTrigger也会重新加载页面

代码如下。

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>

【问题讨论】:

    标签: triggers asp.net-2.0 ajax.net


    【解决方案1】:

    您的代码是正确的,即使在 ASP.NET 2.0 下也能正常运行。由于每个异步回发实际上确实 会回发到页面,我假设您的意思是在安装中单击 Button1 会使页面完全刷新(而不是仅刷新部分)。如果是这种情况,我认为这个问题可能与您的 web.config 中缺少条目有关,这会阻止 ASP.NET Ajax 的客户端部分正确处理部分回发。以下是您应该添加的内容(摘录):

    <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>
    

    【讨论】:

    • 我收到HTTP Error 500.23 - Internal Server Error An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode. 将您的代码添加到我的 web.config 文件中。
    • 那么只需:1) update the setting as asked 或 2) 将应用程序池的管道模式设置为经典而不是集成。
    【解决方案2】:

    我找到了答案。只需将您的应用程序池从DefaultAppPool 更改为ClassicAppPool。这样做一切都应该正常。

    【讨论】:

    • 嘿,这不是您问题的答案。更改管道模式仅在您首先添加处理程序时才有效,正如我在回答中向您展示的那样!
    • 我之前试过你的代码,但它对我不起作用。今天我用谷歌搜索了一整天,发现了一个将 defaultpool 更改为 classicpool 的建议。然后它对我来说很好。你的答案中没有包含这个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-13
    • 1970-01-01
    • 2023-02-25
    • 1970-01-01
    • 2017-01-17
    • 2018-12-25
    • 1970-01-01
    相关资源
    最近更新 更多