Help having problems with UserControl

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
 
T

Tim Wilson

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";
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top