Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

id attribute vs. name attribute

I guess this is more generic than just .NET, but I don't understand the following behavior.

If I give a control an id attribute, I can manipulate it on the client with Javascript, but I can't access it in the Request.Form collection on the server.

If I give a control just a name attribute, I can access it on the server, but am worried about client side support (given that I thought the id attribute was going to totally replace the name attribute).

So my solution is to use both and set them to the same value.

Any thoughts or explanations would be most welcome.

Charles Reich
Monday, June 23, 2003

A "name" is a not-guaranteed-unique identifier for form postbacks. An "id" is a unique identifier inside the DOM for the thing. They don't serve the same (philosophical) purpose. That some old browser decided to let you access things by name in non-standard ways isn't really the point.

Brad Wilson (
Monday, June 23, 2003

My understanding is that ASP.NET controls will automatically be assigned a unique client-side ID in the ClientId property that you can use in scripts if you leave the ID property blank. 

Tuesday, June 24, 2003

Basically if you want your code to work but you still want a valid XHTML page you have to put in both attributes.

Thomas David Baker
Tuesday, June 24, 2003

*  Recent Topics

*  Fog Creek Home