This problem has got me scratching my head.
I have an ASP .NET wizard control. Within the step view, I put a user control. The user control contains a FormView. The Formview contains a mixture of standard ASP .NET controls and other user controls.
In one situation, I have two user controls containing a dropdown list control. I set up an event to fire if the selectedindex of the first dropdown list control changes (which is set to AutoPostback), and the wizard control subscribes to this event. In the event handler of the wizard control, if the first dropdown has a certain value, I want to disable the dropdown in the second user control. So I set up something like this:
private void MyEventHandler(object sender, myeventargs e)
{
//get the formview
FormView _fv = (FormView) this.MainUserControl.FindControl("FormView1");
//get the usercontrol containing the dropdown I want to disable
SecondUserControl _sc = (SecondUserControl) _fv.FindControl("FormViewInsertTemplate_SecondUserControl");
//get the dropdown I want to disable from the second user control
DropDownList _ddl = (DropDownList) _sc.FindControl("SecondDropDown");
//if the dropdownlist in the first user control has the value I want, disable the second dropdown
if (e.SelectedValue == "The Value I Want")
{_ddl.Enabled = false;}
}
Here's the problem. I can't disable the second dropdown. The second dropdown remains enabled.
Now, if I try to disable the second dropdown when the NextButtonClick event fires when moving from the previous wizard stop, using similar code as above, I have no problem. Using FindControl, I can get the dropdown I need to disable it. But when I do this after the controls have been rendered in the step, I can't disable the dropdown on a postback, I can't set it as invisible, I can't change the background color, etc. I don't know why this is the case.
I've tried a number of things to get this to work including:
- Create a property in the usercontrol that contains the dropdown and trying to disable the dropdown from within the usercontrol by setting the property in the wizard control (
this.usercontrol.enabledropdownproperty = false;
) - Rebinding the dropdown
- Trying to save the state of the wizard control after trying to disable the dropdown using both SaveViewState and SaveControlState (my thought being that dropdown wasn't being disabled because it was being retrieved from the viewstate saved prior to the postback)
- Trying to disable both the dropdown and usercontrol (that didn't work either)
- Setting the enable viewstate property for the dropdown, usercontrol, and formview to false, hoping the wizard control viewstate will take care of the child control viewstates
As an experiment, I added a dropdown to the view of another wizard step, setting it to autopostback, and in the selectedindex change event disabling the dropdown. This works! So in my situation, either I'm not getting the correct dropdown to disable, or the fact that it is embedded in a user control is not allowing changes once the control is rendered, or the control is being reinitialized (which I don't think it is because the first dropdown retains the "The Value I Want" value I selected instead of a default value).
Can someone explain why I can disable a dropdown in a usercontrol when moving from a previous wizard step, but I can't disable the dropdown in the postback of the step where I need to disable it, yet I can disable a dropdown in a step postback if the dropdown is an immediate child control of the wizard control (that is to say, not part of a usercontrol, formview, etc.)?