Friday, September 16, 2005

INamingContainer - Custom Controls

Your custom control MUST implement this Marker interface if it needs to handle any of its child control's events.
INamingContainer interface identifies your control as a container control that creates a new ID namespace within a Page object's control hierarchy.

INamingContainer is a marker interface that, when implemented by a control, creates unique IDs for its child controls. This naming scheme guards against potentially dangerous naming collisions. the ASP.NET runtime will throw an exception if a server control inside the page template has the same ID as a control on the calling page.

Ex: Suppose your custom control is given and "custDG" as its ID in the aspx page and that your custom control has a Button control as one of its children.
















 Custom control implements INamingContainer interfaceCustom control does not implement INamingContainer interface
You do not assign any ID to the Custom Control's Child controlinput type="button" name="custDG:_ctl0"

Programmatically, on the server side, you can access the button's ClientID as custDG__ctl0. But it doesn't make any sense on the client side as the Control doesn't output "ID" attribute of the button.
input type="button" name="_ctl0"

Does not fire the server side events of these Child Controls.
You do assign "MyBtn" as the ID to the Custom Control's Child controlinput type="button" name="custDG:MyBtn" ID="custDG_MyBtn"input type="button" name="MyBtn" id="MyBtn".

Does not fire the server side events of these Child Controls.


For a Child Control to save its state in ViewState and load it on postback, it has nothing to do with whether the Custom Control implemented the INamingContainer interface or not.

0 Comments:

Post a Comment

<< Home