Click here to Skip to main content
15,867,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to access usercontrol textbox values to parent form where it has a button and datagridview to add those textbox values
Posted
Updated 11-Apr-18 4:40am
Comments
madhuri@mumbai 16-May-12 6:34am    
You can access value from userControl to Parent page like,
you just create a public property in user control & get value of textbox in that property,like
public string/textbox text
{
get{return txtbox.value;}
}
in parent page:
Parentstring = usercontrol.text;

hope it will help you
Achha Insan 3-Oct-12 5:33am    
nothing is impossible. you can do it.

When you create a child form, you need to create a constructor that receives data. I helped you?
If not here is an example:

C#
string TextboxValue = "";

public Form1()
{
   InitializeComponent();
}

public Form1(string _textboxValue)
{
   InitializeComponent();
   TextboxValue = _textboxValue;
}

And now you have in the variable 'TextboxValue' of type string the value of the Textbox of the parent form.
 
Share this answer
 
Comments
Member 8983639 16-May-12 7:48am    
thanks alot for all of u...... im a begginer just started my career in .net 2 weeks back
MAKReddy 16-May-12 8:08am    
ok all the best
Firstly you need to find Control.
Then With in that control you need to find that textbox.

After that you can access textbox values.

For more Help please Elaborate your Question.
 
Share this answer
 
Comments
Member 8983639 16-May-12 7:45am    
i have four textboxes on the child form(user control) now i need to pass those 4 textbox values to grid on main form. my main form has two controls grid and button on button click this textbox values shud get added
sunandandutt 16-May-12 22:49pm    
Text Boxes are contained on same page in which gridview exists or text boxes are contained in user control and grid view exists in page?
Please Clear my Doubt.
You need to expose public properties or methods of that user control to access values. In the exposed property/method you can write the logic of getting the value. Then you can access this property/Method from the instance of user control that is placed on the designated form.
 
Share this answer
 
Comments
Member 8983639 16-May-12 7:55am    
can u please give me a related example for this?
Finding the control (label) in usercontrol from windows forms

 UserControlmy usrtwo = new UserControlmy();


        Control[] ct;

        public FormUser()
        {
            InitializeComponent();

    //This lbl1 is the label control in the usercontrol UserControlmy . Here we are finding this lbl1 
            ct = usrtwo.Controls.Find("lbl1", true);

        }

       private void Form1_Load(object sender, EventArgs e)
       {

              //This label1 is in form
           label1.Text = ct[0].Text;

       }

Note :: If you find textbox then we have to assign like below

  txtbox1.text=ct[0].text;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900