Click here to Skip to main content
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 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 1 Nov 2012
Copyright © CodeProject, 1999-2014
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