Solved

Updating UserControl with dynamically generated fields

Posted on 2010-09-17
2
300 Views
Last Modified: 2013-11-07
I have a user control which based on 2 properties generates different TextBox entry fields at run time.

There is code in the Page_Init that will take the 2 property values and return the appropriate TextBoxes that should be generated from a database.  

When I hard code the property values of the control on the aspx page it generates the correct TextBoxes.

<uc:SupplementalInfoControl ID="supCtrl" runat="server" Master_Id="1" OS_Typ_Id="22"></uc:SupplementalInfoControl>

But when I try to set the properties at runtime I cannot get it to work correctly.  I've tried setting the properties by supCtrl.Master_Id = 1; and supCtrl.OS_Typ_Id = 22;  I've also tried using binding so:

<uc:SupplementalInfoControl ID="supCtrl" runat="server" Master_Id="<%#GetMasterId() %>" OS_Typ_Id="<%#GetOSTypId() %>"></uc:SupplementalInfoControl>

Where GetMasterId() and GetOSTypId() are pubic methods that return the respective values.

I'm trying to use this control inside of a tab container, I'm able to get it to work if I put it in a popup window and use session variables but I would like to avoid that if possible.  Any help would be appreciated.

Thanks in advance.
0
Comment
Question by:chuck620
2 Comments
 
LVL 6

Accepted Solution

by:
Amritpal Singh earned 500 total points
ID: 33702571
At what moment in the page life cycle are you trying to set the properties of user control. If you are doing it on or after Page_Load , they might not affect User Control's behavior. See the sequence of events

http://forums.asp.net/t/1191194.aspx
0
 

Author Comment

by:chuck620
ID: 33703411
Right now I have a dropdown list, once the selected index changes I'm setting the property.  But at that point the Page_Init & Page_Load have already run.

On the user control in the Page_Init method, I am calling a method to build my dynamic controls.  So I would need the properties set by that point.

I have gotten it to work by setting session variables when the dropdown list index changes, then calling the same method I would call during the Page_Init on the user control and looking for the property values in session.  I just don't like the idea of using Session variables if I don't need to.  I was hoping there was a cleaner way so I don't have to worry about cleaning up the session variables.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now