ASP.Net ITemplate - Announcement Methods

when we want to define a template in our user controls, we declare such a field in our user controls

public ITemplate MyTemplate { get; set; } 

so that the contents of custom templates are presented in MyTemplate and you can use it.

and there are ways to configure templates, for example

 [TemplateInstanceAttribute(TemplateInstance.Single)] public ITemplate MyTemplate { get; set; } 

the above example will allow you to specify individual instance templates ( http://www.nikhilk.net/SingleInstanceTemplates.aspx ).

I accidentally stumbled upon patterns of individual instances and carried it by force.

My question is all that is possible with ITEMplates? how we define them (more precisely, through annotations). Is there any good documentation for ITemplates? (please do not point to msdn)

+3
source share
1 answer

It seems that you are declaring the template correctly. To actually populate the content with your own template, you declare it in your markup. For instance:

 <MyControl runat="server" ...> <MyTemplate> ... any standard ASP.NET controls in here <asp:Label runat="server" ID="lblName"/> </MyTemplate> </MyControl> public void InstantiateIn(Control container) { var lblName = container.FindControl("lblName") as Label; lblName.Text = "Blah";// set from your data layer or otherwise Button b = new Button(); b.ID = "B"; container.Controls.Add(b); } 

Is this what you were looking for?

+1
source

Source: https://habr.com/ru/post/1416166/


All Articles