0

I ma trying to figure out what is the issue here.. when i disable Viewstate for usercontrol inside my updatepanel, its just not updating the content.

here is my code:

if i set Page ViewState-true its working fine but its does not hide it when i need it .

<asp:UpdatePanel ID="CheckoutUpdatePanel" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
         <uc:ClickAndCollect ID="ClickAndCollectPanel" runat="server" Visible="false" EnableViewState="false" />
         </ContentTemplate>
 </asp:UpdatePanel>

======================

My User Control

My UserControl is also wrapped inside updatePanel..

--: it does not have any effect of ViewState even if i disable it. Its just working fine on other page

please help.

Thanks, Milan P

patel.milanb
  • 5,822
  • 15
  • 56
  • 92

2 Answers2

1

when i disable Viewstate for usercontrol inside my updatepanel, its just not updating the content.

Since you're UpdatePanel's UpdateModeis "Conditional", you need to Update it manually.

For example somewhere in an event handler where you want to show/hide it:

ClickAndCollectPanel.Visible = false;
CheckoutUpdatePanel.Update();

UpdatePanel.Update Method

Call the Update method if you have server code that must execute to determine whether an UpdatePanel control should be updated. If you plan to use the Update method, set the UpdateMode property to Conditional. If you want the decision to update the panel in server logic, make sure that the ChildrenAsTriggers property is false and that no explicit triggers are defined for the panel.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • I think update panel requires viewstate for processing control state, even for partial update. – Murali Murugesan Dec 18 '12 at 11:56
  • yes ..i tried with enableviewstate and its working ..but when i need to hide that panel its not hiding.. – patel.milanb Dec 18 '12 at 12:06
  • @patel.milanb: Then i don't understand what _is working_ at all. Are you sure that you don't reset the visible state on every postback somewhere? – Tim Schmelter Dec 18 '12 at 12:08
  • I am not resetting Visible property, if checkbox selected then show user control and if another checkbox selected hide usercontrol. BUT what is happening is when i click another checkbox its still displaying user control contents even when i hiding it on another checkbox checked event. and that is i think because of viewstate. – patel.milanb Dec 18 '12 at 13:20
1
I think you should have ViewState information enabled always 
for doing update with Update Panel.

The update panel will refer the control state using ViewState even 
for partial request. This is why sometimes people say ASP.Net is evil, 
since it sends the whole page view state for every ajax request as parameter. 

So i think update panel/asp.net ajax heavily rely on view state for ASP.Net Ajax

Look

http://encosia.com/why-aspnet-ajax-updatepanels-are-dangerous/

Limiting view state information on AJAX calls

Community
  • 1
  • 1
Murali Murugesan
  • 22,423
  • 17
  • 73
  • 120