LA.NET [EN]

Feb 10

Most of you already know my opinion about this control: it”s good, but if you”re really into AJAX, you should use a client based approach. Now back to the main topic of this post. What will happen when the following page runs:

<form id=”form1″ runat=”server”>
 <asp:ScriptManager runat=”server” id=”manager” />
   <asp:Multiview id=”m” runat=”server” ActiveViewIndex=”0″>
     <asp:View runat=”server” id=”v1″>
        <asp:UpdatePanel runat=”server” id=”panel”>
           <ContentTemplate>
               <asp:button runat=”server” id=”bt” Text=”Change view???” onclick=”Process” />
           </ContentTemplate>
        </asp:UpdatePanel> 
     </asp:View>
     <asp:View runat=”server” id=”v2″>
        <asp:UpdatePanel runat=”server” id=”UpdatePanel1″>
           <ContentTemplate>
               view 2
           </ContentTemplate>
        </asp:UpdatePanel>
      </asp:View>
 </asp:Multiview>
</form>

And yes, from a button click I want to change the view  presented to the user… btw, I”ve also seen some variations which try to set the UpdateMode of both panels to Conditional.

well, this simply doesn”t work. Let”s see what happens when the user clicks on the bt Button:

  1. the buttons starts a postback
  2. the postback is intercepted by the PageRequestManager object
  3. since the button is inside an UpdatePanel, the full postback will be cancelled and we”ll have a partial postback
  4. in the server side, the MultiView will generate the HTML for view 2
  5. while trying to process the returned HTML code on the client side, you”ll get an exception because there”s no UpdatePanel1 in the list of registered panels (remember: during the initial generation of the page, only the 1st UpdatePanel was rendered and that”s why PageRequestManager will only have that panel in its internal list)

Since I”ve mentioned it before, setting the UpdateMode migh give you a corrupted viewstate instead of the error I”ve described before.

After following the previous steps, it”s really simple to understand why this sort of approach really doesn”t work. If you want to dinamically change your view,just wrap the entire MultiView control with an UpdatePanel.

3 comments so far

  1. Li Chen
    9:38 pm - 2-11-2007

    Can you place the MultiView inside an UpdatePanel instead?

  2. Luis Abreu
    9:55 pm - 2-11-2007

    hello. yes, you can. in fact, in the previous example, that”s what you should do if you want to change the view shown to the user without a full postback.

  3. Valentin Vasiliev
    12:03 pm - 6-7-2008

    Thanks, you saved my day!

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>