2

I want to remove parent control (which is span in this case) without deleting its children controls from container. how can I accomplish this in asp.net c#?

you can see the code here: http://pastebin.com/9NiriWXN

Note: I can easily find the "newsright" control and return its parent (which is span in this case)

code master
  • 2,026
  • 5
  • 30
  • 49

1 Answers1

2

You'll need to get the children first and the parent of the parent control and then add the children back to the parent of the parent control.

Shiv Kumar
  • 9,599
  • 2
  • 36
  • 38
  • Control newsControl = FindChildControl(this, "newsright"); Control tempControl = newsControl; Control grand = newsControl.Parent.Parent; int indexatnewparent = newsControl.Parent.Parent.Controls.IndexOf(newsControl.Parent); grand.Controls.RemoveAt(indexatnewparent); grand.Controls.AddAt(indexatnewparent, tempControl); – code master Nov 14 '10 at 19:01
  • The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases. i got this message since this code is in On_Load() – code master Nov 14 '10 at 19:25