Disabled controls don't maintain state
-
I have some radio buttons, I set them to disabled in codebehind, this way the user has only a readonly version of the page controls. However when the page postsback they loose their state. No radio buttons are checked. Usually if the control is enabled upon postback then: Page.Request.Form["myRadioButton2"] == "on" And the ASP .Net engine/parser sets myRadioButton2.Checked = true; However, this Name/Value pair is not in the Page.Request.Form Name/Value collection whenever the control is posted back in a disabled state. I even save its state in SaveViewState() and load it in LoadViewState(); it loads the correct values at first, but then when OnLoad is reached, the ASP .Net engine/parser has sets its state back to the default (Checked = false). Any help on this would be much appreciated. I have this probelm occurring in many areas with many other controls. Always when controls are disabled. CheckBoxLists loose state, DropDownLists loose state as well. Thanks!
-
I have some radio buttons, I set them to disabled in codebehind, this way the user has only a readonly version of the page controls. However when the page postsback they loose their state. No radio buttons are checked. Usually if the control is enabled upon postback then: Page.Request.Form["myRadioButton2"] == "on" And the ASP .Net engine/parser sets myRadioButton2.Checked = true; However, this Name/Value pair is not in the Page.Request.Form Name/Value collection whenever the control is posted back in a disabled state. I even save its state in SaveViewState() and load it in LoadViewState(); it loads the correct values at first, but then when OnLoad is reached, the ASP .Net engine/parser has sets its state back to the default (Checked = false). Any help on this would be much appreciated. I have this probelm occurring in many areas with many other controls. Always when controls are disabled. CheckBoxLists loose state, DropDownLists loose state as well. Thanks!
One option would be to save the checkbox states into a Session variable. It is probably not the best way, but it would result in a solution to the problem. for example: Session("CheckBox1") = CheckBox1.Checked Then, when you reload your page, in Page_Load: if Page.IsPostBack then CheckBox1.Checked = Session("CheckBox1") end if Jon G www.Gizmocoder.com