views:

2713

answers:

3

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

A: 

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!!

Slace
Could you add an explanation as to why using an UpdatePanel is a bad idea? I can think of some but it might be useful for the OP to know more about how UpdatePanels work
Russ Cam
What I think question here is about: the asker want to post only the content page and not the master page. Not sure though.But I would like to know how to do that.
Ismail
A: 

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.

d4nt
+1  A: 

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>
BenAlabaster
Fair Point about the update Panel
cgreeno