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

x
?
Solved

Updating UserControl with dynamically generated fields

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

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

721 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