Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Web User Control setting value of a control
Message
From
31/08/2009 17:02:41
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
ASP.NET
Application:
Web
Miscellaneous
Thread ID:
01421966
Message ID:
01421990
Views:
25
>>OK, I have been down this road before and still not making sense.
>>
>>I have two Web User controls that contain some controls; labels, textboxes, grids.
>>
>>In both controls I have a Setup method that I call after I create the control and before adding it to the page. In the Setup method I am trying to pre-set the value of some of the controls. With the grid I am retrieving data and trying to set the DataSource of the grid. But the grid and all other controls are null in my setup method so I moved them to the Page_Load event. In one of the user controls my contained controls are not null here but in the other user control they are still null in the page load event. This is grief because I can't find a spot where I can setup my controls in they user control the way I want. What other options do I have?
>>Thanks
>>Tim
>
>I don't know if this helps at all or not, but I do something really similar. I have a user control and I have code like this in the Page_Load of it:
>
>
>if (!Page.IsPostback)
>   this.SetDefaults();
>
>
>Then in my main page I load the control dynamically, the properties normally used for my defaults:
>
>
>Control dynControl = Page.LoadControl(userControl);
>ILandingPage landingPage = dynControl as ILandingPage;
>
>if (landingPage != null)
>{
>   landingPage.ContentID = this.m_contentID; // Used by SetDefaults() in the user control
>}
>
>
>The code for adding/removing the controls is called in my Page_Load.

I don't know why but putting this code in the Page_Load event of the control only works on some of the controls but not all of them. I overrode the OnPreRender method and put it there and it seems to work OK. I guess if that is what it takes I should change the others to be consistent but I have compared everything between these controls and I see no difference. Go figure!
Thanks Paul
Tim
Timothy Bryan
Previous
Reply
Map
View

Click here to load this message in the networking platform