By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,928 Members | 1,810 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,928 IT Pros & Developers. It's quick & easy.

Can you load a usercontrol into another usercontrol?

P: n/a
I have an aspx page that loads a usercontrol. Can that usercontrol
load another usercontrol into part of it?
Thanks,
Marv
Jun 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Sure, why not....

George.

<CO*********@lycos.comwrote in message
news:a1**********************************@j22g2000 hsf.googlegroups.com...
>I have an aspx page that loads a usercontrol. Can that usercontrol
load another usercontrol into part of it?
Thanks,
Marv

Jun 27 '08 #2

P: n/a
Yes, just keep in mind that you need to time your events well in the control
event hierarchy. Sometimes an action in a usercontrol that works when
embedded in a page may be a bit off when placed inside another user control.
For example, you pass data from a usercontrol to another one that will show
some more data. You click a link in the parent usercontrol to select a
different set of data to show in the child usercontrol, but the timing of
the events is off so the child usercontrol doesn't update properly and ends
up a step behind the parent.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression

<CO*********@lycos.comwrote in message
news:a1**********************************@j22g2000 hsf.googlegroups.com...
I have an aspx page that loads a usercontrol. Can that usercontrol
load another usercontrol into part of it?
Thanks,
Marv
Jun 27 '08 #3

P: n/a
how do you want to load it?
1.dynamicaly in code behind or
2.insert usercontrol tag in aspx/ascx code?

ad 1)
place the folowing directive in the asp code of the parent page or
usercontrol:

<%@ Reference Control="~/Name_of_your_child_control.ascx" %>
create a new instance in code behind by the following code:

Name_of_your_child_control control = (Name_of_your_child_control)
TemplateControl.LoadControl("~/Name_of_your_child_control.ascx");

ad 2)
place the folowing directive in the asp code of the parent page or
usercontrol:

<%@ Register src="Name_of_your_child_control.ascx"
tagname="Name_of_your_child_control" tagprefix="uc1" %>
use the following tag in the asp-code of the parent page/control:

<uc1:Name_of_your_child_control ID="Name_of_your_child_control1"
runat="server" />

Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.