Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to reference a control in user control?
Message
 
 
À
04/02/2010 11:22:14
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01447396
Message ID:
01447531
Vues:
19
>>>Hi,
>>>
>>>I assume you are referring to using the control in a form ? If so you will need to expose the TextBox as a public property of the UserControl:
 public TextBox MyTextBox
>>>        {
>>>            get { return txtMyEntry; }
>>>            set { txtMyEntry = value; }
>>>        }
Then, in the form you can reference it as MyUserControlName.MyTextBox.Text etc. But you might consider only exposing those properties of the TextBox that you want to be accessible in this way - the above may be too flexible
>>>HTH
>>>Viv (temporarily in disguise since my logon's not working :-}
>>

I tried to add your code (changing to my names) but I am getting compile error on the line set { txtMyEntry = value; }

Let me clarify something. I replaced the names "txtMyEntry" in your code above with my textbox name ("this.txtMyTextBox"). The error says that "Cannot implicitly convert type "System.Windows.Forms.TextBox to MyNameSpace.My_TextBox_class. An explicit conversion exists (are you missing a cast?)"

What am I missing?
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform