Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Placing identical controls on to the page using the Placingholder control makes them disappear

Reply
Thread Tools

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

 
 
alun65@gmail.com
Guest
Posts: n/a
 
      07-16-2007
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
-----------------

<asplaceholder ID="Placeholder1" runat="server"></asplaceholder>
<asplaceholder ID="Placeholder2" runat="server"></asplaceholder>


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


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

Thanks in advance for any help.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      07-16-2007
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
> -----------------
>
> <asplaceholder ID="Placeholder1" runat="server"></asplaceholder>
> <asplaceholder ID="Placeholder2" runat="server"></asplaceholder>
>
>
> Expected output
> ------------------------
> 1 1
>
>
> Actual output
> -------------------
> 1
>
> Thanks in advance for any help.
>
>

 
Reply With Quote
 
 
 
 
alun65@gmail.com
Guest
Posts: n/a
 
      07-16-2007
Yep that's is what I was trying to do. This make sense now. Thanks
Peter.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid Paging makes DataGrid Disappear smithb1028 ASP .Net 7 01-28-2007 08:59 PM
Editing any of gridviews on a page makes bound controls in datalist disappear. HP ASP .Net 0 11-30-2006 06:00 AM
Outlook Express Messages Disappear, Bookmarks in Internet Explorer Disappear rchrdcarlisle@NOTyahoo.com Computer Support 19 07-30-2006 09:41 PM
Changing image on an ImageButton makes by button disappear abarberis@gmail.com ASP .Net 2 01-11-2005 10:04 PM
Putting image in <div> makes menu disappear! Kyle James Matthews HTML 2 04-23-2004 08:24 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57