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

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

Post by alun6 » Wed, 18 Jul 2007 01:37:00


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.
 
 
 

1. Editing any of gridviews on a page makes bound controls in datalist disappear.

2. Dynamic Controls in User Control; page/control lifecycle question

I have a user control into which I insert a bunch of controls dynamically. I
have it all working just fine - Everything is there on Postback, etc.

I load this user control into a hosting ASPX page at runtime during the
Page_Load event procedure of the hosting ASPX page.

Question: Would it be better to load the user control from the hosting
page's OnInit event rather than Page_Load? Does it matter or not?

I ask because I understand that for dynamic controls to be properly
inserted - it must be done during the OnInit event - which is happening -
but only in the ASCX lifecycle (which gets kicked off from the hosting aspx
page_load).

Thanks.

3. Controlling page height real estate used by TreeView Control

4. Using inner controls from a tab page control

5. using javascript in User controls to access server controls of the user control

6. Message box breaks owner draw controls in .NET controls used as ActiveX controls (again)

7. using controls in user control as control parameters on parent

8. using controls in user control as control parameters on parent pag

9. Compile errors when using form control's "Control Source" property to refer to the control's value

10. modify visibility of master page controls from pages user control?

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

12. Can a multi view control be used in a page that uses a master page?

13. Tab Control Pages showing controls on all pages!

14. Showing 1 control inside a 2nd control where the 2nd control is a derived control.