• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

How do you copy objects from one placeholder into another..

In my sample i wanted to create another placeholder with the same objects in it and place it in a different part of the page but for some reasons i could not just say phMyLinks=phMyLinks2 . I also tried to populate both placeholders at run time but it was populating only one of them. One way was  to explicitely create another LinkButton and to make all actions parallel to both placeholders. I am looking to find an easier solution whereas i could populate both placeholders altogether  .

Label lblPage=new Label();
lblPage.Text="Page : ";
for(int i=1;i<=pageTotal;i++)
      myLink=new LinkButton();
      myLink.Text=" " + Convert.ToString(i) + " ";
      myLink.Click+=new EventHandler(myLink_Click);
      phMyLinks.Controls.Add(myLink);  //this becomes empty

2 Solutions
I think that a given control/object can only exist within one PlaceHolder (or one containing object) at a time.  (Otherwise, that control's Parent property would get rather confused.)  You may have to build two copies of each control so that you can place one into each PlaceHolder.
This article talks about cloning: http://www.ondotnet.com/pub/a/dotnet/2002/11/25/copying.html?page=2
It may help you to understand what you're trying to do and why its not easilly possible.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now