What does the INamingContainer Inteface do?

  • Thread starter Thread starter gemel
  • Start date Start date
G

gemel

Interface definitions do no not contain implementation, only
signtures. That is there real purpose. Here thow we have an Inteface
which does not have any implementation code but it has to be included
in the creation of a Web User Control. Please tell me how it actually
does something?

Regards

John L
 
It's a marker interface..I'm not 100% sure how it works, but if you check
out how the constructor control work, you'll see:

if (this is INamingContainer){
this.flags[0x80] = true;
}


as you can see, it checks if the control implements INamingContainer, and if
it does, it sets a flag to a value...that's typically how marker interfaces
work...something checks if the object implements the interface, and if it
does, some magic is handled....how that's used from then on end, I'm not
sure....but what it actually does it ensure that controls are given unique
ids...this is important if you are creating composite controls or something
where you are specifying an ID for the dynamically created
child-controls...if you don't implement INamingContainer and you drop the
control twice on the same page (say for paging at the top and bottom of a
repeater), you'll have conflicting control IDs...INamingContainer ensures
that controls have a unique name. Additionally, without this uniqueness,
you'll likely run into problems with postback events not firing properly
because control Ids won't be appropriate...

HTH
Karl
 
Perferct answer :)


Karl Seguin said:
It's a marker interface..I'm not 100% sure how it works, but if you check
out how the constructor control work, you'll see:

if (this is INamingContainer){
this.flags[0x80] = true;
}


as you can see, it checks if the control implements INamingContainer, and if
it does, it sets a flag to a value...that's typically how marker interfaces
work...something checks if the object implements the interface, and if it
does, some magic is handled....how that's used from then on end, I'm not
sure....but what it actually does it ensure that controls are given unique
ids...this is important if you are creating composite controls or something
where you are specifying an ID for the dynamically created
child-controls...if you don't implement INamingContainer and you drop the
control twice on the same page (say for paging at the top and bottom of a
repeater), you'll have conflicting control IDs...INamingContainer ensures
that controls have a unique name. Additionally, without this uniqueness,
you'll likely run into problems with postback events not firing properly
because control Ids won't be appropriate...

HTH
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


gemel said:
Interface definitions do no not contain implementation, only
signtures. That is there real purpose. Here thow we have an Inteface
which does not have any implementation code but it has to be included
in the creation of a Web User Control. Please tell me how it actually
does something?

Regards

John L
 
Hi...

From the MSDN documentation:

"Any control that implements this interface creates a new namespace in which
all child control ID attributes are guaranteed to be unique within an entire
application. The marker provided by this interface allows unique naming of
the dynamically generated server control instances within the Web server
controls that support data binding. These controls include the Repeater,
DataGrid, DataList, ListBox, CheckBoxList, HtmlSelect, and RadioButtonList
controls."

Basically, this interface causes the ASP.NET runtime to do it's job relative
to control naming. It is a "marker" interface, meaning that some piece of
code, e.g., the ASP.NET runtime, will use its presence to take some action.

Hope this helps.

John Puopolo
..NET Fan
 
Back
Top