How do I persist visibility of a panel control across postbacks?
Posted on 2007-07-25
My tools: Visual Web Developer, SQL Server 2005, VB.net back coding
I have a formview control that defaults to 'edit' mode when the form starts.... on formview1 there is button1 that makes panel1 become visible. On panel1 there is radiobuttonlist1 that has 2 options; NULL and A....radiobuttonlist1 is bound to an SQL table datafield that initially has no value (NULL).....so, the default selection for the radiobuttonlist is NULL. The radiobuttonlist1 has 'autopostback' = True.
So, after the button click, panel1 becomes visible with NULL already pre-selected....if the user selects A then the postback occurs making textbox1 visible where they are to enter some data.
Here is the code in RadioButtonList1 selectedindexchanged:
Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
FormView1.FindControl("Panel1").Visible = True
HERE IS MY PROBLEM:
If I select option A from radiobuttonlist1, no problem.... option A gets selected and the textbox becomes visible.... BUT, if I change my mind and try to re-select the NULL option , the entire panel disappears. Why does it do this? According to the sub, any index change of the radiobuttonlist should persist visibility of panel1.
No matter how this radiobuttonlist is set up and no matter what the default value is that populates it from the SQL table, if I make an attempt to return to the radiobuttonlist default value (cause a second postback) the panel disappears despite the code that tells it to be visible.....
Any help is appreciated....thanks.