User controls dissapear after PostBack
Posted on 2008-10-06
I need a bit of advice here please.
I have a Panel control on my web page.
Depending on certain conditions I have various user controls that suppose to show up in that Panel.
For example if button A is clicked I execute mainPanel.Controls.Add(userControl1);
If button B is clicked I execute manlPanel.Controls.Add(userControl2);
All user controls have their own "Submit" buttons.
The problem is that User Controls disappear from the Panel once the Submit button is pressed and it does not do what the control is suppose to be doing.
I am aware that the page is completely refreshed during the postback causing my user controls disappear from the panel.
How would you handle/ resolve this issue though ? I can't just bind user controls to the Panel on the Page_Load event as I have to determine which control to load based on the Button selected on my Web Page.
Thank you in advance and let me know if any of this isn't clear.