473,322 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 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 1562
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.