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

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
 
G

Guest

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
 

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
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top