I have two drop down lists where one is inside an update panel and the other is outside.When the Index is changed on ddlFaculty the whole page is posted back instead of a partial for the contents in the update panel.
我有两个下拉列表,其中一个在更新面板内,另一个在外面。当在ddlFaculty上更改索引时,整个页面将被回发而不是部分更新面板中的内容。
I have read in the ASP docs that sometime validation controls bog down update panels but im not too sure if that's the problem here.
我在ASP文档中读到,有时验证控件会使更新面板陷入困境,但我不太确定这是否是问题所在。
<div class="form-group">
<asp:Label runat="server" AssociatedControlID="ddlFaculty" CssClass="col-md-2 control-label">Faculty</asp:Label>
<div class="col-md-10">
<asp:DropDownList ID="ddlFaculty" EnableViewState="true" class="form-control" CausesValidation="false" runat="server" autopostback="true" aria-expanded="true" ValidationGroup="g4" OnSelectedIndexChanged="ddlFaculty_SelectedIndexChanged">
<asp:ListItem Value="null">Select Faculty</asp:ListItem>
<asp:ListItem Value="Arts">Faculty of Arts</asp:ListItem>
<asp:ListItem Value="Business">Faculty of Business</asp:ListItem>
<asp:ListItem Value="Health">Faculty of Health</asp:ListItem>
<asp:ListItem Value="Industries">Faculty of Service Industries</asp:ListItem>
<asp:ListItem Value="Trades">Faculty of Trades</asp:ListItem>
<asp:ListItem Value="Maori">Te Wananga Maori</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator runat="server" ControlToValidate="ddlFaculty" ValidationGroup="g4"
CssClass="text-danger" Display="Dynamic" ErrorMessage="The faculty field is required." />
</div>
</div>
<div class="form-group">
<asp:Label runat="server" AssociatedControlID="ddlCourse" CssClass="col-md-2 control-label">Course</asp:Label>
<div class="col-md-10">
<asp:UpdatePanel runat="server" id="UpdatePanel1" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label runat="server" id="lblfaculty"></asp:Label>
<asp:DropDownList runat="server" CssClass="form-control" ID="ddlCourse" ValidationGroup="g7" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlFaculty" EventName="SelectedIndexChanged"/>
</Triggers>
</asp:UpdatePanel>
<asp:RequiredFieldValidator runat="server" ControlToValidate="ddlCourse" ValidationGroup="g7"
CssClass="text-danger" Display="Dynamic" ErrorMessage="The course field is required." />
</div>
</div>
2 个解决方案
#1
Try using the AsyncPostBackTrigger
property of the UpdatePanel
.
尝试使用UpdatePanel的AsyncPostBackTrigger属性。
See: How to stop UpdatePanel from causing whole page postback?
请参阅:如何阻止UpdatePanel导致整页回发?
Did you try setting Button1 as an AsyncPostBackTrigger in the Triggers section, set the ChildrenAsTriggers property to true and the UpdateMode property to Conditional
您是否尝试在触发器部分中将Button1设置为AsyncPostBackTrigger,将ChildrenAsTriggers属性设置为true,将UpdateMode属性设置为Conditional
Other solutions:
User control inside update panel causing full page postback
更新面板内的用户控件导致整页回发
Full postback happens if your UpdatePanel cannot render its contents to a (e.g., when it is situated inside of ). So check you html inside of UpdatePanel, you might find the answer there (also, look for some incorrect xhtml, like incorrectly closed elements).
如果您的UpdatePanel无法将其内容呈现给a(例如,当它位于其中时),则会发生完全回发。所以检查一下UpdatePanel里面的html,你可能会在那里找到答案(另外,找一些不正确的xhtml,比如错误关闭的元素)。
UpdatePanel causes full page postback
UpdatePanel导致整页回发
Unless you know of known issues that your site has when running in XHTML mode (and which you don't have time yet to fix), I'd always recommend removing the section from your web.config file (or you can explicitly set it to "Transitional" or "Strict").
除非您知道您的网站在XHTML模式下运行时遇到的已知问题(以及您还没有时间修复),我总是建议您从web.config文件中删除该部分(或者您可以明确地设置它“过渡”或“严格”)。
This will make your HTML output standards compliant. Among other things, this will cause the HTML from your server controls to be "well formed" - meaning open and close tag elements always match. This is particularly important when you are using AJAX techniques to dynamically replace the contents of certain HTML elements on your page (otherwise the client-side JavaScript sometimes gets confused about container elements and can lead to errors). It will also ensure that ASP.NET AJAX works fine with your site.
这将使您的HTML输出标准符合要求。除此之外,这将导致服务器控件中的HTML“格式良好” - 意味着打开和关闭标记元素始终匹配。当您使用AJAX技术动态替换页面上某些HTML元素的内容时,这一点尤为重要(否则客户端JavaScript有时会对容器元素产生混淆并导致错误)。它还将确保ASP.NET AJAX与您的站点一起正常工作。
#2
It turns out that the page was infact sending a partial postback but I had mistaken the scroll to the top of the page when the postback had been recieved as a full page post back
事实证明,该页面实际上发送了部分回发,但是当回发作为整页回发收到后,我错误地将滚动条错误地翻到了页面顶部
#1
Try using the AsyncPostBackTrigger
property of the UpdatePanel
.
尝试使用UpdatePanel的AsyncPostBackTrigger属性。
See: How to stop UpdatePanel from causing whole page postback?
请参阅:如何阻止UpdatePanel导致整页回发?
Did you try setting Button1 as an AsyncPostBackTrigger in the Triggers section, set the ChildrenAsTriggers property to true and the UpdateMode property to Conditional
您是否尝试在触发器部分中将Button1设置为AsyncPostBackTrigger,将ChildrenAsTriggers属性设置为true,将UpdateMode属性设置为Conditional
Other solutions:
User control inside update panel causing full page postback
更新面板内的用户控件导致整页回发
Full postback happens if your UpdatePanel cannot render its contents to a (e.g., when it is situated inside of ). So check you html inside of UpdatePanel, you might find the answer there (also, look for some incorrect xhtml, like incorrectly closed elements).
如果您的UpdatePanel无法将其内容呈现给a(例如,当它位于其中时),则会发生完全回发。所以检查一下UpdatePanel里面的html,你可能会在那里找到答案(另外,找一些不正确的xhtml,比如错误关闭的元素)。
UpdatePanel causes full page postback
UpdatePanel导致整页回发
Unless you know of known issues that your site has when running in XHTML mode (and which you don't have time yet to fix), I'd always recommend removing the section from your web.config file (or you can explicitly set it to "Transitional" or "Strict").
除非您知道您的网站在XHTML模式下运行时遇到的已知问题(以及您还没有时间修复),我总是建议您从web.config文件中删除该部分(或者您可以明确地设置它“过渡”或“严格”)。
This will make your HTML output standards compliant. Among other things, this will cause the HTML from your server controls to be "well formed" - meaning open and close tag elements always match. This is particularly important when you are using AJAX techniques to dynamically replace the contents of certain HTML elements on your page (otherwise the client-side JavaScript sometimes gets confused about container elements and can lead to errors). It will also ensure that ASP.NET AJAX works fine with your site.
这将使您的HTML输出标准符合要求。除此之外,这将导致服务器控件中的HTML“格式良好” - 意味着打开和关闭标记元素始终匹配。当您使用AJAX技术动态替换页面上某些HTML元素的内容时,这一点尤为重要(否则客户端JavaScript有时会对容器元素产生混淆并导致错误)。它还将确保ASP.NET AJAX与您的站点一起正常工作。
#2
It turns out that the page was infact sending a partial postback but I had mistaken the scroll to the top of the page when the postback had been recieved as a full page post back
事实证明,该页面实际上发送了部分回发,但是当回发作为整页回发收到后,我错误地将滚动条错误地翻到了页面顶部