Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello guys.! I'm having hard time here trying to solve this problem.
I Have a Userctrl(button)inside a form

In my usercontrol. i have this code..

C#
public UserControl1()
        {
            InitializeComponent();

        }

        public string branch { get; set; }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(branch + "");
        }


and in my FORM


C#
private void Form2_Load(object sender, EventArgs e)
        {
            UserControl1 usr = new UserControl1();
            usr.branch= "Boom";
          
        }



PROBLEM : When i hit the usrctrl button in my form. The popup msg is empty. XD. I don't know why. did i missed something?
Posted

1 solution

damn. I solved my own question :(

I just should not make an new object for my usercontrol. instead call it directly.

C#
string str = textBox1.Text;
            userControl11.branch = str;


Now its working :)
 
Share this answer
 
Comments
CPallini 16-May-14 4:12am    
Of course, my 5. By the way, you should give meaningful names (like, for instance, "foo" :-) ) to your variables.<br>
Zj Pineda 22-May-14 3:38am    
next time :D

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