开发者

Question on custom templated controls

I read about templated controls/INamingContainer but I can't understand what problem it solves when making a custom control. Does it simply allow me to use ItemTemplate (like the DataGrid does)?

Reference link: http://msdn.microsoft.com/en-us/library/36574bf6.aspx

On this link, it says "Any control t开发者_运维百科hat implements this interface creates a new namespace in which all child control ID attributes are guaranteed to be unique within an entire application.", so really, this interface is for composite controls and not custom controls which are not composite?

Thanks


The problem it solves is that all server control ID's have to be unique. Consider a simple composite control that adds a textbox to itself called "Textbox1".

If you add two of these composite controls to the page, there will be two controls called "Textbox1" on the page, which violates the uniqueness, and hence ASP.Net's ability to manage and maintain these textboxes on the server side.

By appending the container namespace to them, you get a unique name. In this case you'd get something like "myCompositeControl_Textbox1" and "myCompositeControl2_Textbox1".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜