Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Placing identical controls on to the page using the Placingholder control makes them disappear (http://www.velocityreviews.com/forums/t522352-placing-identical-controls-on-to-the-page-using-the-placingholder-control-makes-them-disappear.html)

alun65@gmail.com 07-16-2007 04:37 PM

Placing identical controls on to the page using the Placingholder control makes them disappear
 
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=?= 07-16-2007 06:00 PM

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



"alun65@gmail.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.
>
>


alun65@gmail.com 07-16-2007 06:54 PM

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.



All times are GMT. The time now is 04:54 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.