Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

User controls dissapear after PostBack

Posted on 2008-10-06
4
Medium Priority
?
732 Views
Last Modified: 2013-12-17
Hi Experts.

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.
0
Comment
Question by:techsuppoprt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 22652756
I suppose the problem is that you add user control to panel only once and do not do this after postback.

If I were you I'd add all user contols into panel and control their visibility instead of adding them to panel on the same conditions.
If button A is pressed set all user controls Visible = false and userControl1.Visible = true.

Just that simple

R
0
 
LVL 7

Accepted Solution

by:
imateyelectronics earned 2000 total points
ID: 22652832
Is passing the information back to the page via a hidden field out of the question?
0
 
LVL 13

Expert Comment

by:crazyman
ID: 22653190
Controls must be re-added for each postback.

http://www.singingeels.com/Articles/Dynamically_Created_Controls_in_ASPNET.aspx

When the page first gets a button click store the required control name in viewstate, on subsequent postbacks check this to see what control needs re-adding to the control tree, i suggest you do this in CreateChildControls on OnInit.
0
 
LVL 1

Author Closing Comment

by:techsuppoprt
ID: 31503529
QUick and simple.. don't know how I didn't think of that.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question