Click here to Skip to main content
10,500,000 members (77,560 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# User-controls
hello,

I have a c# user control. I have a button in this control, and I want that when the user clicks on the button, another user control will be opened.

How can I do that?

Thanks
Posted 1-Nov-12 0:02am
Edited 1-Nov-12 0:03am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

What user control is that?
Is it a Windows Application or Web Application?
You can use Properties of Visible to hide or show the control.
protected void Button1_Click(object sender, EventArgs e)
{
    userControl1.Visible = !userControl1.Visible;
}
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I don't understand what you mean with 'open user control', but you can show, hide, add and remove controls.

Show controls[^]
Hide controls[^]
Add controls[^]
Remove controls[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Please try the following code

Window win = new Window();
UserControl1 eDoc = new UserControl1();
win.Content = eDoc;
win.Title = "User Control1";
win.Show();

Hope be helpful,
Theingi
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

In your button click event, create a control and add it in the collection

myOwnControl userControl1 = new myOwnControl ();
this.Controls.Add(userControl1);

-Milind
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 489
1 OriginalGriff 328
2 Mehdi Gholam 145
3 Sascha Lefèvre 135
4 KarstenK 115
0 Sergey Alexandrovich Kryukov 9,308
1 OriginalGriff 8,352
2 Sascha Lefèvre 3,334
3 Maciej Los 2,956
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 1 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100