0

我有一个简单的 ASP.NET UpdatePanel,它在我运行 Visual Studio (Casini) 时按预期工作。

但是,一旦部署到我的本地 IIS,它就不再工作了。

什么配置错误?

我的代码:

<!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:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Button1" />
            </Triggers>
        </asp:UpdatePanel>
    </div>
    <input id="Text1" type="text" />
    </form>
</body>
</html>

...和代码隐藏:

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

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

        }

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

在 Casini 中,标签会在没有回发的情况下更新。在 IIS 上,会发生回发。

4

2 回答 2

1

在 web.config 文件的 Handlers 部分添加以下行:

<add name="Ajax" verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>

于 2012-06-13T06:12:59.630 回答
0

ASP.NET AJAX 要求网页与 XHTML 兼容(不是 HTML 4.0)。事实上,在 web.config 中没有 mode=Transitional 将阻止 scriptManager 甚至在页面中呈现,并且每次 AJAX 命中都会像常规回发一样。

放入 web.config xhtmlConformance mode="Transitional"/>

Chk链接它应该可以帮助你

于 2012-06-13T06:09:14.407 回答