PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

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

 
 
Dan
Guest
Posts: n/a
 
      2nd Jan 2004
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


 
Reply With Quote
 
 
 
 
Christophe Gijbels
Guest
Posts: n/a
 
      4th Jan 2004
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.LoadControl("OtherUserControl.asc
x"));

where default is the name of your page class

Christophe


"Dan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to refer a control in the host page from a user control if the host page using masterpage Jerry Qu Microsoft ASP .NET 1 20th Feb 2009 07:41 PM
how do you embed a windows media player control in a user control and have it work in a web page? dongarbage@hotmail.com Microsoft C# .NET 0 26th Jan 2007 06:52 AM
Page load of the parent page called twice when a modal dialog is opened from a button click of the user control on the parent page Samy Microsoft ASP .NET 2 15th Aug 2005 04:30 PM
Dynamic Controls in User Control; page/control lifecycle question Frankie Microsoft ASP .NET 2 23rd Jun 2005 05:07 PM
accessing the web user control's control from a web page and set a value from another web page Reny J Joseph Thuthikattu Microsoft ASP .NET 1 30th Dec 2004 12:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:39 PM.