469,962 Members | 2,301 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Add control to asp:PlaceHolder on asp.net page from user control on same page

Dan
I have an asp.net page default.aspx with a user control and a placeholder
control.

<html>
<body>
<form id="myform" method="post" runat="server" />
<PageHeader:Header id="header1" runat="server" />
<asp:PlaceHolder ID="content" runat="server" />
</form>
</body>
</html>

In my user control I have 5 linkbuttons. I would like to have each of these
linkbuttons load a different user control into the placeholder on the
default.aspx page. Is this possible? If so how can I add my user controls
to the placeholder from another user control?

Thanks,

Dan
Nov 18 '05 #1
1 2735
You've got different options. Just make sure you can modify the controls
collection of the placeholder control on the page. You can do this in
different ways. You can create a public property or method on the page
class, and by the Page property on your usercontrol, you can invoke the page
method or work with the property. You could also let your page class pass
the reference of the placeholder, or the placeholders control collection, to
a property on your usercontrol.

if you would use a method on the page class then you could do something like
this

default.aspx.cs

public void SetPlaceHolderControl (Control control) {
content.Controls.Clear();
content.Controls.Add(control);
}

in your header usercontrol put something like this in the eventhandler of
the linkbuttons

((default)Page).SetPlaceHolderControl(Page.LoadCon trol("OtherUserControl.asc
x"));

where default is the name of your page class

Christophe
"Dan" <da******@test.com> wrote in message
news:O8**************@TK2MSFTNGP10.phx.gbl...
I have an asp.net page default.aspx with a user control and a placeholder
control.

<html>
<body>
<form id="myform" method="post" runat="server" />
<PageHeader:Header id="header1" runat="server" />
<asp:PlaceHolder ID="content" runat="server" />
</form>
</body>
</html>

In my user control I have 5 linkbuttons. I would like to have each of these linkbuttons load a different user control into the placeholder on the
default.aspx page. Is this possible? If so how can I add my user controls to the placeholder from another user control?

Thanks,

Dan

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

23 posts views Thread by Lamberti Fabrizio | last post: by
2 posts views Thread by Brett Robichaud | last post: by
3 posts views Thread by 200dogz | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.