Solved

Updating UserControl with dynamically generated fields

Posted on 2010-09-17
2
301 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

18 Experts available now in Live!

Get 1:1 Help Now