Retaining the dynamic controls
-
Hi, I have an issue with creating dynamic controls and retaining them when the page refreshes. The situation is like this.On the Page_load i creating few sets of questions along with choices(Using radio buttons "Yes" and "No").All the radio buttons are dynamically created.For the first question, if the user clicks the "No" radiobutton, i shud show one more question with a "Checkbox", which should be dynamically created on the selection of "No" radiobutton.The same question pattern repeats for 3 times.So for the first question of each set the above condition should apply.What i did was when i created the "No" radiobutton of first question of each set, i made the "Autopostback" to true and attached one event handler with that, which will create the checkbox dynamically.But what happens is that, when i click the "No" radiobutton of the first question of the second set of questions, the checkbox created when we clicked the first set "No" radiobutton will vanish and a new checkbox will come near to the second set.What i need is to retain the first checkbox also.I found that when i'm clciking the Second "no" button the page reloads and the first checkbox is not retained.(Remember the checkbox creation is attached with the corresponding "no" button click). Also i can't use "Session" to retain the controls that i created, since my application wont support Session variables. Please help me in finding an optimal solution. Thanks in advance! Thanks & Regards, V.Sathyanarayanan
-
Hi, I have an issue with creating dynamic controls and retaining them when the page refreshes. The situation is like this.On the Page_load i creating few sets of questions along with choices(Using radio buttons "Yes" and "No").All the radio buttons are dynamically created.For the first question, if the user clicks the "No" radiobutton, i shud show one more question with a "Checkbox", which should be dynamically created on the selection of "No" radiobutton.The same question pattern repeats for 3 times.So for the first question of each set the above condition should apply.What i did was when i created the "No" radiobutton of first question of each set, i made the "Autopostback" to true and attached one event handler with that, which will create the checkbox dynamically.But what happens is that, when i click the "No" radiobutton of the first question of the second set of questions, the checkbox created when we clicked the first set "No" radiobutton will vanish and a new checkbox will come near to the second set.What i need is to retain the first checkbox also.I found that when i'm clciking the Second "no" button the page reloads and the first checkbox is not retained.(Remember the checkbox creation is attached with the corresponding "no" button click). Also i can't use "Session" to retain the controls that i created, since my application wont support Session variables. Please help me in finding an optimal solution. Thanks in advance! Thanks & Regards, V.Sathyanarayanan
Start with the simple stuff. Make sure you have the EnableViewState property set to true on the disappearing controls. Also make sure that you have all your initial page_load code within an if block to check for postback, i.e.
if (!this.IsPostBack)
. If that doesn't work, you can always check the value's of subsequent buttons and checkboxes on postback and repopulate prior buttons and checkboxes accordingly.- Arcond