472,978 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,978 software developers and data experts.

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 1545
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave Veeneman | last post by:
Is there a simple way to pass drag-and-drop events to a child control in a UserControl? Here's an example: I have created a UserControl which contains a treeview and some text boxes. I want to...
8
by: Raed Sawalha | last post by:
Hi, I have a strange problem with a usercontrol on a page. The usercontrol dispalyes three categories (From a database) when the user clicks a category they see all the products in a shop for...
2
by: Sascha | last post by:
Hi there, I searched carefully through the web before finally deciding to post this message, because I could not find a solution for my problem. Hopefully someone will have a hint or explanation...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
9
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it...
1
by: Jibber | last post by:
Sorry for the similar post, but I have clarified the problem a bit more. The issue is: how do I use an extended .NET control in a webform using VS2005. In my case, I am overriding the Render for a...
6
by: MeowCow | last post by:
I have created a UserControl that encapsulates a third party data grid. My goal was to create my own DataSource and DataMember properties that forward the binding to the third party grid, then use...
10
by: Benton | last post by:
Hi there, I have a UserControl with a couple of textboxes and a couple of buttons ("Save" and "Cancel"). The Click event for this buttons is in the UserControl's codebehind of course, so here's...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.