Solved

Updating UserControl with dynamically generated fields

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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