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?
If you disable ViewState, and a page needs it, the page will no longer work.
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.
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With