How to get Server control to access parent container's controls collection?
-
Hello. Is there any way a custom server control can can programmatically add controls to the parent pages controls collection? I've tried the following...
protected override void Render(HtmlTextWriter writer) { this.Page.Controls.Add(new HtmlGenericControl("div")); .... }
...but it gives me an error "Collection was modified; enumeration operation may not execute.". I've also tried adding the above code into the OnPreRender and OnInit events but it still gives me an error, this time "The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.". What I am trying to do is get a server control to add a div tag to the parent page but positioned just after the opening body tag or just before the closing body tag, just so that it's not wrapped in any other elements basically. Something tells me this isn't possible but thought I'd ask you folks before I gave up on this.Dominic Pettifer Blog: www.dominicpettifer.co.uk
-
Hello. Is there any way a custom server control can can programmatically add controls to the parent pages controls collection? I've tried the following...
protected override void Render(HtmlTextWriter writer) { this.Page.Controls.Add(new HtmlGenericControl("div")); .... }
...but it gives me an error "Collection was modified; enumeration operation may not execute.". I've also tried adding the above code into the OnPreRender and OnInit events but it still gives me an error, this time "The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.". What I am trying to do is get a server control to add a div tag to the parent page but positioned just after the opening body tag or just before the closing body tag, just so that it's not wrapped in any other elements basically. Something tells me this isn't possible but thought I'd ask you folks before I gave up on this.Dominic Pettifer Blog: www.dominicpettifer.co.uk