ASP Web server controls and ID attributes

  • Thread starter Thread starter Neil Zanella
  • Start date Start date
N

Neil Zanella

Hello,

My understanding is that when using ASP.NET web server controls and
HTML controls the ID attribute becomes a global variable. But isn't
there a way to assign a local variable within a for loop? That is,
isn't there an equivalent of the ID property which can act as a
local variable. BTW I have used the ID property within a for
loop so that several controls got the same ID but IIS did
not complain, which I find strange. Perhaps someone can
clarify this issue.

Thanks,

Neil
 
On server controls, either Web Server Controls or HTML Controls with
Runat=Server, the ID functions as the name of the protected field that
represents the control object. It has to be unique.

I'd be interested in seeing more details of what you've done and what you're
trying to do. Otherwise, it is really not clear what the answer to your
question is.

DalePres
MCAD, MCSE, MCDBA
 
Well, if all ID attributes are supposed to be different from each
other,
than how would you explain the following quote taken directly from
the MSDN documentation?

<quote>
NamingContainer (inherited from Control) Gets a reference to the server
control's naming container, which creates a unique namespace for
differentiating between server controls with the same Control.ID
property value.
</quote>

Thanks,

Neil
 
This is for controls like repeater or datagrid, which may contain other
server controls in thier templates. For exmaple, when you place a textbox in
the ItemTemplate of a DataGrid, this same control appears in all items of the
grid.
Otherwise you CANNOT have two different controls with the same ID in one page.

Regards,
Kostadin Kostov
 
Kostadin is correct. And let me add one more bit to what he says. In
addition to repeaters, datagrids, etc., if you have multiple copies of a
single user control, then each user control may have, for instance, a
"textbox1". That is another case of why the unique ID is created, to
differientiate between them.

DalePres
 
Back
Top