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

  • Thread starter Thread starter alun65
  • Start date Start date
A

alun65

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
 
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
 
Back
Top