views:

140

answers:

3

Why when a control does contain value but it's set to .Enable=False that all controls become disable (that's ok) but why that the ViewState doesn't retain the data on the next post back? If I get the UserControl without modifing its Enable state, the ViewState work between post back.

How can we disable a UserControl that all its control become disable (this part work) but all of them KEEP use the ViewState (this doesn't work)?

Clarification:

1)In the aspx.cs click button EDIT:

myControl.Enabled = false;
//This produce to have all controls in myControl to be disabled.

2)In the asp.cs: click Save to leave the EDIT state:

myControl.Enabled = true;
//This produce that all controls inside myControl are blank : no viewstate!

Other postback works because we do not put myControl.Enable to false.

A: 

Have you tried Page.Form.SubmitDisabledControls = true;

MIchael Grassman
+3  A: 

Specifying .Enable=False is like a server-side disable, NOT a client-side disable. This is for security purposes so you can truly disable an input element even if the user uses some client-side trickery to "re-enable" it. If you want to perform a client-side disabling, you'll need to use script for that, or perhaps use a readonly attribute.

Jaxidian
A: 

This is by design, if you want the control to use ViewState and still be disabled, then you have disable the control on the ClientSide. I use the Page.ClientScript to handle this and register your javascript to disable the control.

Gary L Cox Jr