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”>
<asp:button runat=”server” id=”bt” Text=”Change view???” onclick=”Process” />
<asp:View runat=”server” id=”v2″>
<asp:UpdatePanel runat=”server” id=”UpdatePanel1″>
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:
- the buttons starts a postback
- the postback is intercepted by the PageRequestManager object
- since the button is inside an UpdatePanel, the full postback will be cancelled and we”ll have a partial postback
- in the server side, the MultiView will generate the HTML for view 2
- 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.