views:

24

answers:

2

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

+1  A: 

This article explains how to use ControlState. Maybe you need to override the SaveControlState method to save TemplateField data in ControlState.

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

JohnB
in the control state
Bob Fincheimer
SO isn't the text box's values stored in the control state? Shouldn't I be able to access them regardless of what the GridView's View State is?
Bob Fincheimer
`ControlState` is separate from `ViewState` (although `ControlState` is stored in the ugly `ViewState` object - so you still see `ViewState` when you set `EnableViewState=false`). I believe Joel is right, and you have to program the `ControlState` specifically to save the `TemplateField` data.
JohnB
+1  A: 

The control doesn't manage its own state from PostBack to PostBack. That's what the ViewState is for. The controls in the Gridview are bound from data stored in the viewstate unless you bind the control on every PostBack (inadvisable).

Joel Etherton