Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to reference control in UC from page?
Message
De
10/04/2006 17:54:54
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01111711
Message ID:
01112206
Vues:
19
Dmitry,

Sometimes it is sufficient simply to have a public field, but this doesn't always work for everything.

The Get/Set methods are basically what makes it a Property. In order for stuff to show up on Property Sheets, they need to be specifically defined as a Property. Some other things also require Properties (DataBinding in WinForms is one good example).
private string m_MyProperty;

public string MyProperty
{
  get {return this.m_MyProperty;}
  set {this.m_MyProperty = value;}
}
Your book will probably do a better job of explaining Properties <g> but I thought I'd just give you a brief description anyway.

~~Bonnie



>Bonnie,
>
>Thank you very much. I actually finally figured how to do it. That is, I have the result I was looking for.
>
>But to be honest, I still have a problem to fully understand the concept of Property Set and Get. I plan to read on it more (in the book on C# I have) tonight. I will read slow and out load if I have to <g>.
>
>>Dmitry,
>>
>>For a great conversion tool, check out: http://www.carlosag.net/Tools/CodeTranslator/ You can convert in both directions, VB-to-C# or C#-to-VB. What you'll get is this:
>>
>>public System.Web.UI.WebControls.Label dbVersion {
>>        get {
>>            return this.dbVersion;
>>        }
>>    }
>>
>>
>>
>>~~Bonnie
>>
>>
>>>>>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"
>>>>
>>>>Dmitry,
>>>>
>>>>In the code-behind for the ASCX, declare a public (or protected withfriend) property that directly references the actual control:
>>>>
>>>>
>>>>
>>>>Public Class MyUserControl
>>>>    Inherits System.Web.UI.UserControl
>>>>
>>>>Public ReadOnly Property dbVersion() As System.Web.UI.WebControls.Label
>>>>    Get
>>>>        Return Me.dbVersion
>>>>    End Get
>>>>End Property
>>>>
>>>>...
>>>>
>>>
>>>Keith,
>>>
>>>First, thank you so much for your help.
>>>
>>>How do you convert the code:
>>>
>>>
>>>Public ReadOnly Property dbVersion As System.Web.UI.WebControls.Label
>>>
>>>
>>>to C#?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform