ASP.NET Custom/User Control With Children -


I have to create a custom / user control that is child.

For example, I want to control my bottom markup:

  & lt; Div runat = "server" id = "div" & gt; & Lt; Label runat = "server" id = "label" & gt; & Lt; / Labels & gt; & Lt; Div class = "field" & gt; & Lt ;! - Include children here - & gt; & Lt; / Div & gt; & Lt; / Div & gt;  

And when I want to use it on a page I:

  & lt; Ctr: MyUserControl runat = "server" id = "myControl" & gt; ; & Lt; Span & gt; This is a child & lt; / Span & gt; & Lt; Div runat = "server" id = "myChild" & gt; And the second & lt; B & gt; Hair & lt; / B & gt; & Lt; / CTR: MyUserControl & gt;  

The control of the child in my user control will be put in my user control anywhere. What is the best way to accomplish this?

The functionality is similar to a placeholder: ASP, but I want to add some extra options, as well as additional markups and such. Apart from this, the child should still be able to access the page to control. (In the above example of the page should have my child control on it)

Edit ------

It may be a template control until it references me Allows to give children on the page.

I had said something like this some time ago. See

I believe you must use an ITemplate as an InnerProperty. [PeristenceMode.InnerProperty] [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)] [TemplateInstance (Template instances. Single)] Public ITEM content {get {return_content; } Set {_content = value; }} Private ITemplate _content;

Then override the CreateChildControls method of your control:

  Protected Override Zero CreateChildControls () (if (this.Content! = Null) {this. Controls .Specific (); this.Content.InstantiateIn (this);} Base.CreateChildControls ();}  

Is there a loss in using a ITemplate You can combine it with your existing markup and type content inside whatever you want HTML property.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -