Search code examples
asp.netviewstate

When is safe to disable viewstate?


When is safe to disable viewstate? For which controls? Under what circumstances?

In a user control I have disabled viewstate, but if I attempt to click in this control

<asp:LinkButton ID="LinkButton1" runat="server" 
  CommandName="Delete" 
  OnClientClick="return confirm('¿Está seguro que desea eliminar el mensaje?');"
  EnableViewState="true">
    <asp:Image ID="ImageButton1" runat="server" ImageUrl="~/Content/Images/delete.png" 
        ToolTip="Eliminar mensaje" /> Eliminar 
</asp:LinkButton>

I get an System.InvalidOperationException exception. It is inside a ListView.


Solution

  • Most controls behave as you would expect with viewstate disabled. The more 'dynamic' controls with built in functionality like Gridviews tend not to play well without viewstate.

    Are you sure that the exception is related to the viewstate given that you have the enableviewstate property set to true on your control?