Master Pages and Postback in ASP.NET

狂风中的少年 提交于 2019-12-11 14:17:36

问题


How can we avoid Master Page from posting back the whole page?


回答1:


Just to clarify - the update panel doesn't prevent a whole page postback or a full page lifecycle. It just causes that process to be completed in the background "unseen" to the user. The only difference is that upon completion of the postback only the section wrapped by the update panel declaration is refreshed, thus causing the illusion that only part of the page is posted back.

If the trigger control is inside the updatepanel then you should set the ChildrenAsTriggers attribute equal to True. If the control that triggers the update is outside the update panel, then you should add the Triggers section to the control panel and add an asynchronous trigger. If it is a combination, then you could combine the two for the best effect.

If the control that triggers the update is contained inside the update panel:

<asp:UpdatePanel id="MyUpdatePanel" runat="server" ChildrenAsTriggers="True">
  <ContentTemplate>
    ...Stuff you want updated
  </ContentTemplate>
</asp:UpdatePanel>

Or if the control isn't contained inside the update panel:

<asp:UpdatePanel id="MyUpdatePanel" runat="server">
  <ContentTemplate>
    ...Stuff you want updated
  </ContentTemplate>
  <Triggers>
    <asp:AsyncPostBackTrigger ControlID="MyButtonControl" EventName="Click" />
  </Triggers>
</asp:UpdatePanel>



回答2:


Using a master page doesn't really have any effect on whether the whole page posts back or not. A simple ASPX page with no master and a standard would do a whole page postback too.

Reading between the lines though, I'm guess that your master page has some UpdatePanels on it already (perhaps surrounding the content placeholders) that prevent the whole page from refreshing when something inside them causes a postback.

Either way, the key to preventing a full page refresh (whether using master pages or not) is to make sure that the control that causes the postback lives inside an UpdatePanel or use some JavaScript to call back to the server and process the response asynchronously.




回答3:


The Master Page isn't responsible for the PostBack, that's what the HTML form is for.

The only way you could prevent a page from posting back would be to wrap the entire thing in an UpdatePanel. But that itself is a really bad idea!!



来源:https://stackoverflow.com/questions/388493/master-pages-and-postback-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!