Help having problems with UserControl

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that has a button in it when I click on the button I want the
textbox that is on the usercontrol to update. Ive tried:
//This is on the form
private void button1_Click(object sender, System.EventArgs e)
{
UserControl1 ctrl = new UserControl1();
ctrl.ClientName = "This is a test";
}
//This is on the usercontrol
public string ClientName
{
get
{
return this.textBox1.Text;
}
set
{
this.textBox1.text = value;
}
}
when I check the value is in the textbox but it doesn't update itself or
fire the event can someone tell me what Im doing wrong.
Thanks
Kim
 
Unless the code that you're posting is some sort of pseudo code, it looks
like your creating an instance of your UserControl inside the Button Click
handler instead of using the instance that is on the Form.

private UserControl1 userControl1 = new UserControl1();

....

private void button1_Click(object sender, System.EventArgs e)
{
userControl1.ClientName = "This is a test";
}
 
Back
Top