If I have misunderstood your concerns, don't hesitate to let me know.
Page1
protected void Page_Load(object sender, EventArgs e)
{
Contents con = new Contents();
Panel pan = new Panel();
con.FillContents(pan);
this.Form.Controls.Add(pan);
}
Class Contents
class Contents
{
public void FillContents(Panel p)
{
Controls_MyCtl myCtl = new Controls_MyCtl();
p.Controls.Add(myCtl);
}
}
class Controls_MyCtl
class Controls_MyCtl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox box = new TextBox();
this.Controls.Add(box);
}
}
Please mark the replies as answers if they help or unmark if not.
Feedback to us
fineware
0 Points
1 Post
instanciating and resolving a user control in App_Code
May 05, 2012 10:47 AM|LINK
Using Visual Studio 2010 / c#: I created a user control.
class Controls_MyCtl : System.Web.UI.UserControl
In App_Code, I have a class with a function which has a panel control passed in:
public void FillContents(Panel p)
In FillContents, I want to instanciate a Controls_MyCtl and add it to the passed in Panel.
I can't figure out what I need to do for Controls_MyCtl to be resolved.
ramiramilu
All-Star
95295 Points
14072 Posts
Re: instanciating and resolving a user control in App_Code
May 05, 2012 11:45 AM|LINK
TestUserControl tuc = (TestUserControl)Page.LoadControl("~/TestUserControl.ascx");
tuc.ID = "uc1";
Panel1.Controls.Add(tuc);
for the above needs to be done in your class file, your might need to add Using namespaces to class file...
Thanks,
JumpStart
Frank Jiang ...
All-Star
16006 Points
1728 Posts
Microsoft
Re: instanciating and resolving a user control in App_Code
May 08, 2012 06:37 AM|LINK
Hi,
If I have misunderstood your concerns, don't hesitate to let me know.
Page1
protected void Page_Load(object sender, EventArgs e) { Contents con = new Contents(); Panel pan = new Panel(); con.FillContents(pan); this.Form.Controls.Add(pan); }Class Contents
class Contents { public void FillContents(Panel p) { Controls_MyCtl myCtl = new Controls_MyCtl(); p.Controls.Add(myCtl); } }class Controls_MyCtl
class Controls_MyCtl : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { TextBox box = new TextBox(); this.Controls.Add(box); } }Feedback to us
Develop and promote your apps in Windows Store