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

D

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
 
A

Alessandro Zifiglio

hi dan,
a much better solution would be to have a controlID in your querystring.
This way you use a normal hyperlink button and pass a different id for every
link that is click and then retrieve it on your default page and structure
out from there in page_load--this way you can load controls from the default
page itself.

so in default.aspx page load you can do something like this :
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim controlID As String
Dim c1 As Control
controlID = Request.QueryString("controlID")
Select Case controlID
case "control1"
c1 = LoadControl("my_control_name.ascx")
PlaceHolder1.Controls.Add(c1)
case "control2"
c1 = LoadControl("my_control_name.ascx")
PlaceHolder1.Controls.Add(c1)
case "control3"
c1 = LoadControl("my_control_name.ascx")
PlaceHolder1.Controls.Add(c1)
case "control4"
c1 = LoadControl("my_control_name.ascx")
PlaceHolder1.Controls.Add(c1)
case "control5"
c1 = LoadControl("my_control_name.ascx")
PlaceHolder1.Controls.Add(c1)
case else
Dim lblerror As New Label()
lblerror.Text = "How did you get here ;)"
PlaceHolder1.Controls.Add(lblerror)
End select
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,263
Messages
2,571,064
Members
48,769
Latest member
Clifft

Latest Threads

Top