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

Discussion in 'ASP .Net' 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. 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" <> 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
    >
    >
    Christophe Gijbels, Jan 4, 2004
    #2
    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. Carlos Cruz

    Add control to a placeholder

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

    Build control in a placeholder or like a placeholder

    nail, Sep 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    321
  5. Dan
    Replies:
    3
    Views:
    786
    Alessandro Zifiglio
    Jan 21, 2004
Loading...

Share This Page