I have a grid view with a nested text box in it. I would like to turn view state off but the fact of the matter is when data is posted, the text boxes inside the gridview aren’t available (there are no rows in the gridview on postback).
I am using ASP.NET 2.0 so would this fall into control state, not view state?
Sample ASPX code of the gridview:
<asp:GridView runat="server" ID="myGridView">
<Columns>
<asp:TemplateField ItemStyle-Wrap="false" HeaderText="Name">
<ItemTemplate>
<asp:TextBox runat="server" ID="myTextBox" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
EDIT
Control’s information is not stored in the View State (for things like selected value and .text etc.):
Control state, introduced in ASP.NET version 2.0, is similar to view state but functionally independent of view state. A page developer can disable view state for the page or for an individual control for performance. However, control state cannot be disabled. Control state is designed for storing a control’s essential data (such as a pager control’s page number) that must be available on postback to enable the control to function even when view state has been disabled.
Source: http://msdn.microsoft.com/en-us/library/1whwt1k7.aspx
This article explains how to use ControlState. Maybe you need to override the
SaveControlStatemethod to saveTemplateFielddata inControlState.Search for “Disadvantage of using control state are:” in this article:
“Some programming is required. While the ASP.NET page framework provides a foundation for control state, control state is a custom state-persistence mechanism. To fully utilize control state, you must write code to save and load control state.”
Also maybe helpful:
Control State vs. View State Example
ASP.NET State Management Overview