Placing identical controls on to the page using the Placingholder control makes them disappear

Discussion in 'ASP .Net' started by alun65@gmail.com, Jul 16, 2007.

  1. Guest

    I've been implementing some paging links that I would like at the
    bottom and top of a result set, I build up the required HTML in the
    code behind then add it to the placeholder.

    This works fine when there only one placeholder on the page but as
    soon as I add another it seems to all about the last placeholder
    control.

    I've got a simple example which illustrates my point, here we add a
    link to the page via the code behind then add it to two
    Placeholder's, but we only see it output once.

    Default.aspx.cs
    ------------------------
    protected void Page_Load(object sender, EventArgs e)
    {
    HtmlAnchor Link = new HtmlAnchor();
    Link.InnerText = "1 ";
    Placeholder1.Controls.Add(Link);
    Placeholder2.Controls.Add(Link);
    }

    Default.aspx
    -----------------

    <asp:placeholder ID="Placeholder1" runat="server"></asp:placeholder>
    <asp:placeholder ID="Placeholder2" runat="server"></asp:placeholder>


    Expected output
    ------------------------
    1 1


    Actual output
    -------------------
    1

    Thanks in advance for any help.
     
    , Jul 16, 2007
    #1
    1. Advertising

  2. RE: Placing identical controls on to the page using the Placingholder

    I think this is because you are attempting to add the same instance of the
    control into the page twice. Create two link, each with its own unique ID
    property (e.g. "link1" and "link2") and add the two different links each to
    the two different placeholders. The links can point to the same page - they
    just need to be separate instances.
    --Peter
    Recursion: see Recursion
    site: http://www.eggheadcafe.com
    unBlog: http://petesbloggerama.blogspot.com
    bogMetaFinder: http://www.blogmetafinder.com



    "" wrote:

    > I've been implementing some paging links that I would like at the
    > bottom and top of a result set, I build up the required HTML in the
    > code behind then add it to the placeholder.
    >
    > This works fine when there only one placeholder on the page but as
    > soon as I add another it seems to all about the last placeholder
    > control.
    >
    > I've got a simple example which illustrates my point, here we add a
    > link to the page via the code behind then add it to two
    > Placeholder's, but we only see it output once.
    >
    > Default.aspx.cs
    > ------------------------
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > HtmlAnchor Link = new HtmlAnchor();
    > Link.InnerText = "1 ";
    > Placeholder1.Controls.Add(Link);
    > Placeholder2.Controls.Add(Link);
    > }
    >
    > Default.aspx
    > -----------------
    >
    > <asp:placeholder ID="Placeholder1" runat="server"></asp:placeholder>
    > <asp:placeholder ID="Placeholder2" runat="server"></asp:placeholder>
    >
    >
    > Expected output
    > ------------------------
    > 1 1
    >
    >
    > Actual output
    > -------------------
    > 1
    >
    > Thanks in advance for any help.
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Jul 16, 2007
    #2
    1. Advertising

  3. Guest

    Re: Placing identical controls on to the page using the Placingholder

    Yep that's is what I was trying to do. This make sense now. Thanks
    Peter.
     
    , Jul 16, 2007
    #3
    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. Replies:
    2
    Views:
    472
  2. Kyle James Matthews

    Putting image in <div> makes menu disappear!

    Kyle James Matthews, Apr 23, 2004, in forum: HTML
    Replies:
    2
    Views:
    1,756
  3. HP
    Replies:
    0
    Views:
    438
  4. smithb1028

    DataGrid Paging makes DataGrid Disappear

    smithb1028, Jan 27, 2007, in forum: ASP .Net
    Replies:
    7
    Views:
    1,461
    smithb1028
    Jan 28, 2007
  5. bill
    Replies:
    2
    Views:
    96
    kaeli
    Aug 6, 2004
Loading...

Share This Page