Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable ViewState for child custom controls when disabled in parent?

I am trying to create a custom control that a "gridview" like control but specifcally for business objects that implement certain custom interfaces.

In doing this I have come across the following problem.

I have a control that I have disabled viewstate on (and I don't want to re-enable it) and it has a child control that I want viewstate enabled on. I can't seem to get the viewstate on the child control to work since its parents is disabled. Does anyone have any ideas of how to get that to work?

like image 305
Bob Dizzle Avatar asked Oct 06 '08 17:10

Bob Dizzle


People also ask

What happens when ViewState is disabled?

If you disable ViewState, and a page needs it, the page will no longer work.

Which property is used to disable enable ViewState of control at page level?

To disable ViewState for a page To disable ViewState for a single page, set the EnableViewState attribute in the @ Page directive to false, as in the following: <%@ Page Language="C#" EnableViewState="false" AutoEventWireup="true" CodeFile="URLRouting.

What is the use of Enable ViewState property?

View state enables a server control to maintain its state across HTTP requests. View state for a control is enabled if all of the following conditions are met: The EnableViewState property for the page is set to true . The EnableViewState property for the control is set to true .


1 Answers

You cannot enable viewstate on a control which is within another control that has viewstate disabled.

Your only option is to enable it for the outer control, and then turn it off for all of the controls within it, except for the control you need viewstate.

EnableViewState property on any container will override the behavior of all controls within that containter.

Good Luck!

EDIT: You may want to look at your CreateChildContols() method and enumerate the controls disabling viewstate from there for each of the controls within the custom control using the EnableViewState property.

like image 149
Jason Stevenson Avatar answered Nov 03 '22 00:11

Jason Stevenson