-3

I've made a C# user control with one textbox.

How can I access the property of read only from outside the user control. thanks

sAnS
  • 1,169
  • 1
  • 7
  • 10
dark knight
  • 11
  • 1
  • 6

1 Answers1

2

expose your textbox as a public property in the userControl and access it wherever you have used the usercontrol.

for example:

public class MyUserControl : UserControl
    {
           public TextBox MyTextBox 
           {
               get
               {
                  return txtBox1;
               }
               set
               {
                   txtBox1 = value;
               } 
           }
    }

and to make it readonly do this:

myUserControl.MyTextBox.ReadOnly=true; //where myUserControl is instance of 
                                       //MyUserControl, you have used somewhere
Manish Mishra
  • 12,163
  • 5
  • 35
  • 59