【发布时间】:2011-05-30 22:35:15
【问题描述】:
我在让 UpdatePanel 在大型现有解决方案中工作时遇到问题。我有一个示例页面(如下),它可以在新创建的 demo 网站中使用,但在添加到现有 target 网站时无法使用。
功能是隔离下拉菜单的自动回发,所以我不会丢失 FileUpload ASP 控件的内容(它为security reasons 执行此操作,一些解决方案为described here)
在 target(非演示)站点中,控件添加到页面精细(inc intellisense),页面呈现 - 但更改下拉菜单仍然执行回发,而不是 ajax - 化下拉框。
提到的target解决方案之前是从 ASP.NET v1.1 升级的,所以我想知道我在配置中是否缺少某些东西? p>
我在呈现的 HTML 源代码中可以找到的唯一区别是非工作版本没有添加 PageRequestManager,例如:
<script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ctl02', document.getElementById('form1'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tctl03'], [], [], 90);
//]]>
</script>
示例页面:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager2" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DropDownList runat="server" ID="TestDropDown" AutoPostBack="true" OnSelectedIndexChanged="TestDropDown_SelectedIndexChanged">
<asp:ListItem>One</asp:ListItem>
<asp:ListItem>Two</asp:ListItem>
<asp:ListItem>Three</asp:ListItem>
</asp:DropDownList>
<asp:Literal runat="server" Text="Original state" ID="litText" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:FileUpload ID="FileUpload2" runat="server" />
</div>
</form>
</body>
</html>
在后面的代码中:
protected void TestDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
litText.Text = "Ajax update. The file details should still be present below";
}
我可以确认 ScriptManager 标记将以下内容添加到页面源中,因此我假设 Ajax Toolkit 已添加:
if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.');
我们在 web.config 中有以下部分:
<compilation defaultLanguage="c#" debug="true">
<assemblies>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
[...]
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, [...]
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions" [...]
[...]
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
示例在 demo 站点中没有
【问题讨论】:
标签: asp.net asp.net-ajax updatepanel postback