ASP Web server controls and ID attributes

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
 
D

DalePres

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
 
N

nzanella

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
 
G

Guest

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
 
D

DalePres

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top