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

Discussion in 'ASP .Net Web Controls' started by Dan, Jan 2, 2004.

  1. Dan

    Dan Guest

    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
    Dan, Jan 2, 2004
    #1
    1. Advertising

  2. 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
    "Dan" <> wrote in message
    news:%...
    > 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
    >
    >
    Alessandro Zifiglio, Jan 2, 2004
    #2
    1. Advertising

  3. Dan

    Gerald Klein Guest

    Please be more specific

    "Steve_Funk" <> wrote in message
    news:...
    >
    > How do you pass parameters to the User Control?
    >
    >
    > Steve_Funk
    > ------------------------------------------------------------------------
    > Posted via http://www.mcse.ms
    > ------------------------------------------------------------------------
    > View this thread: http://www.mcse.ms/message237830.html
    >
    Gerald Klein, Jan 21, 2004
    #3
  4. This was a cross post actually, which finished on the buildingControls
    group, see if the it helps you in anyway, otherwise postback ;)
    http://groups.google.com/groups?hl=...ge&ie=UTF-8&oe=UTF-8&hl=en&btnG=Google+Search


    "Gerald Klein" <> wrote in message
    news:%...
    > Please be more specific
    >
    > "Steve_Funk" <> wrote in message
    > news:...
    > >
    > > How do you pass parameters to the User Control?
    > >
    > >
    > > Steve_Funk
    > > ------------------------------------------------------------------------
    > > Posted via http://www.mcse.ms
    > > ------------------------------------------------------------------------
    > > View this thread: http://www.mcse.ms/message237830.html
    > >

    >
    >
    Alessandro Zifiglio, Jan 21, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan
    Replies:
    1
    Views:
    5,395
    Christophe Gijbels
    Jan 4, 2004
  2. Carlos Cruz

    Add control to a placeholder

    Carlos Cruz, Apr 11, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    399
    Ken Cox [Microsoft MVP]
    Apr 12, 2004
  3. David Hubbard
    Replies:
    2
    Views:
    824
    David Hubbard
    Jan 12, 2006
  4. Dan
    Replies:
    5
    Views:
    347
  5. nail

    Build control in a placeholder or like a placeholder

    nail, Sep 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    331
Loading...

Share This Page