UpdatePanel - No errors, but web.config settings required?
I'm having issues getting UpdatePanel working in a large, existing solution. I have a sample page (below), which works in a freshly created demo website, but not when added to the existing target website.
The functionality is to isolate a dropdown's auto-postback, so I don't lose the contents of a FileUpload ASP control (it does this for security reasons, with some solutions described here)
In the target (non-demo) site, the control adds to the page fine (inc intellisense), and the page renders - but changing the drop down still performs a postback, rather than ajax-ifying the dropdown box.
The target solution mentioned was previously upgraded from ASP.NET v1.1, so I'm wondering if there's something I'm missing in the configuration?
The only difference I can find in the rendered HTML source is that the non-working version doesn't add the PageRequestManager, e.g.:
<script type="text/javascript">
//<![CDATA[
Sys.WebForms.PageRequestManager._initialize('ctl02', document.getElementById('form1'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tctl03'], [], [], 90);
//]]>
</script>
Sample page:
<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>
And in the code behind:
protected void TestDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
litText.Text = "Ajax update. The file details should still be present below";
}
I can confirm that the ScriptManager tag adds the following to the page source, so I assume the Ajax Toolkit has been added:
if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.');
And that we have the following sections in web.config:
<compilation defaultLanguage="c#" debug="true">
<assemblies>
<add assembly="System.Web.Extensions, Versio开发者_运维技巧n=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>
The sample works in the demo site without the <Triggers> section, but I've tried adding it to the target site, to no avail.
Turns out the following should not be set in web.config, and occurs as a result of the upgrade from ASP.NET v1.1:
<xhtmlConformance mode="Legacy"/>
As discussed on ScottGu's blog post
精彩评论