468,512 Members | 1,625 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

including UserControl in UserControl

How can I include an usercotrol into an other usercontrol...
for example:

<UserControl:First runat="server" id="firstUC" content="..." />

and i want to refer an other UserControl (e.g. called "Second") to the
property "content" of usercontrol "First".
Thanks for help
Nov 19 '05 #1
4 1385
If you want to dynamically load it, you'd do something like:

public class First : UserControl
{
private string _innerContentPath;
public string InnerContentPath{
get { return _innerCOntentPath; }
set { _innerContentPath = value;
}
Page_Load()
{
if (_innerContentPath != null)
{
Control InnerControl = Page.LoadControl(_innerContentPath);
SomePlaceHolder.Controls.Add(InnerControl);
}
}

so then you would do
<UserControl:First runat="server" id="FirstUC"
InnerContentPath="SomeOtherUserControl.ascx" />

Hope I didn't misunderstand..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Alexander Widera" <aw**@hrz.tu-chemnitz.de.invalid.de> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
How can I include an usercotrol into an other usercontrol...
for example:

<UserControl:First runat="server" id="firstUC" content="..." />

and i want to refer an other UserControl (e.g. called "Second") to the
property "content" of usercontrol "First".
Thanks for help

Nov 19 '05 #2
You can easily nest User Controls by placing one on another. To get to
properties, however, you will have to expose teh embedded controls properties
with properties in the embedding control. Otherwise, the page does not have
direct access. Remember to add a code behind reference if you are
programatically setting values.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Alexander Widera" wrote:
How can I include an usercotrol into an other usercontrol...
for example:

<UserControl:First runat="server" id="firstUC" content="..." />

and i want to refer an other UserControl (e.g. called "Second") to the
property "content" of usercontrol "First".
Thanks for help

Nov 19 '05 #3
Just in case you did misunderstand, Karl, the other approach would be to
dynamically load the seond Control into the first via the Page:

// Assuming the UserControl FirstControl is in a tag in the Page
protected FirstUserControlType FirstControl;
private SecondUserControlType SecondControl;
public void Page_Load()
{
SecondControl = LoadControl("SecondControlType.ascx");
FirstControl.Controls.Add(SecondControl);
}

I hope at least ONE of us didn't misunderstand!

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
I'd rather be a hammer than a nail.

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OV*************@TK2MSFTNGP10.phx.gbl...
If you want to dynamically load it, you'd do something like:

public class First : UserControl
{
private string _innerContentPath;
public string InnerContentPath{
get { return _innerCOntentPath; }
set { _innerContentPath = value;
}
Page_Load()
{
if (_innerContentPath != null)
{
Control InnerControl = Page.LoadControl(_innerContentPath);
SomePlaceHolder.Controls.Add(InnerControl);
}
}

so then you would do
<UserControl:First runat="server" id="FirstUC"
InnerContentPath="SomeOtherUserControl.ascx" />

Hope I didn't misunderstand..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Alexander Widera" <aw**@hrz.tu-chemnitz.de.invalid.de> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
How can I include an usercotrol into an other usercontrol...
for example:

<UserControl:First runat="server" id="firstUC" content="..." />

and i want to refer an other UserControl (e.g. called "Second") to the
property "content" of usercontrol "First".
Thanks for help


Nov 19 '05 #4
well,
Karl got it right :)

thanks a lot

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> schrieb im Newsbeitrag
news:%2******************@TK2MSFTNGP15.phx.gbl...
Just in case you did misunderstand, Karl, the other approach would be to
dynamically load the seond Control into the first via the Page:

// Assuming the UserControl FirstControl is in a tag in the Page
protected FirstUserControlType FirstControl;
private SecondUserControlType SecondControl;
public void Page_Load()
{
SecondControl = LoadControl("SecondControlType.ascx");
FirstControl.Controls.Add(SecondControl);
}

I hope at least ONE of us didn't misunderstand!

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
I'd rather be a hammer than a nail.

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:OV*************@TK2MSFTNGP10.phx.gbl...
If you want to dynamically load it, you'd do something like:

public class First : UserControl
{
private string _innerContentPath;
public string InnerContentPath{
get { return _innerCOntentPath; }
set { _innerContentPath = value;
}
Page_Load()
{
if (_innerContentPath != null)
{
Control InnerControl = Page.LoadControl(_innerContentPath);
SomePlaceHolder.Controls.Add(InnerControl);
}
}

so then you would do
<UserControl:First runat="server" id="FirstUC"
InnerContentPath="SomeOtherUserControl.ascx" />

Hope I didn't misunderstand..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Alexander Widera" <aw**@hrz.tu-chemnitz.de.invalid.de> wrote in message news:eq**************@TK2MSFTNGP09.phx.gbl...
How can I include an usercotrol into an other usercontrol...
for example:

<UserControl:First runat="server" id="firstUC" content="..." />

and i want to refer an other UserControl (e.g. called "Second") to the
property "content" of usercontrol "First".
Thanks for help




Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Dave Veeneman | last post: by
8 posts views Thread by Raed Sawalha | last post: by
2 posts views Thread by Sascha | last post: by
12 posts views Thread by Joe | last post: by
9 posts views Thread by Marcelo Cabrera | last post: by
6 posts views Thread by MeowCow | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.