User Control in Windows Application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Limno
    New Member
    • Apr 2008
    • 92

    User Control in Windows Application

    I created my user control for email validation in windows application(C# language).I am using it in the form, if the user leave that textbox it ll show message "E-Mail expected",if its correct value, then it ll be stored in another textbox. How can i retrieve values from the user control into textbox.
    Eg. textbox1.text=U serControl1.tex t; But its not working.

    Is there anyother way to use that usercontrol....

    Thanks in Advance.
  • balame2004
    New Member
    • Mar 2008
    • 142

    #2
    Your source code is wrong If your user control contains a textbox to enter email id.

    The best way to retrieve value of text property of a textbox added in an user control is as follows.

    this.TextBox1.T ext=UserControl 1.TextBox1.Text ;

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Or if your user control will only have one Text property you would be referring too, you could add a public Text property to the user control. That way when you ask for UserControl1.Te xt, it gives you the text of it's textbox.

      Code:
      public string Text
      {
           get
           {
               return textbox1.text;
           }
           set
           {
               textbox1.text = value;
           }
      }

      Comment

      • Limno
        New Member
        • Apr 2008
        • 92

        #4
        Code:
        public string Text
        {
             get
             {
                 return textbox1.text;
             }
             set
             {
                 textbox1.text = value;
             }
        }
        if i use this code, Hope this code must written some class. How could i call the value in form1...

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          You put it in your custom control.

          From Form1 you call it from your reference to the custom control.

          Code:
          NiftyControl bob = new NiftyControl();// This is the instance of your custom control.
          String email = bob.Text;// This is the Text property you just made that really gets its value from the TextBox.Text that is *on* your custom control

          Comment

          Working...