Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to reference control in UC from page?
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01111711
Message ID:
01113189
Views:
14
Dmitry,

Bonnie has given you one way to do this, but I would argue that's not a good idea because you are breaking encapsulation. You shouldn't expose child controls in a user control in this fashion to the parent.

Either the child control should manage all interaction with the values itself, or the child control should republish the appropriate values as properties that can be accessed from the parent control.

In your situation I would probably create a property called dbVersion and
then expose from it the VALUE (not the control) of the control it's bound to:

In hte user controL
public string dbVersion
{
   get {  return this.txtdbVersion.Text; } 
}
If you find that your control needs to publish a lot of values in this fashion you should re-examine your interface and think about refactoring logic most likely into the usercontrol itself.


+++ Rick ---

>I need to reference an ASP label which is in the User Control, from the code in the page.
>
>The page has declaration of the user control, at the top of the pages, as:
>
>
>< %@ Register TagPrefix="uc1" TagName="Header" Src="Header.ascx" % >
>
>
>In the HTML of the page the user control declaration code is:
>
>
><uc1:Header id="Header1" runat="server"></uc1:Header>
>
>
>The user control has ASP label as:
>
>
><asp:Label ID="DbVersion" Runat=server></asp:Label>
>
>
>And I want from the OnLoad method of the page to set value of this label. Pseudo code:
>
>uc1.Header1.dbVersion.text = "My Version"
>
>How do I do it?
>
>Thank you in advance.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform