Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Updating UserControl with dynamically generated fields

Posted on 2010-09-17
2
Medium Priority
?
320 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 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

773 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