Calendar

<<  décembre 2008  >>
lumamejevesadi
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

(février 22, 2008 08:15)

In the project I currently work in, I see a few confusion between the use of UniqueID and ClientID we can do server-side or client-side. So it's time to recall the differences between the two.

If you have a Textbox (runat server) with an Id, let's say "MyControl", you will have

  • UniqueId : ctl00$MyControl
  • ClientId : ctl00_MyControl

where

  • the prefix (here "ctl00") will vary depending of the nesting of INamingContainer controls
  • "$" is a constant, defined in Control.IdSeparator and that may be overriden in the page itself ot in the web.config file
  • "_" is a constant, defined in Control.ClientIDSeparator (and that may be overriden in control's derived classes)

What does it will generate client side ?

<input name="ctl00$MyControl" type="text" id="ctl00_MyControl" />

So to be brief :

  • UniqueID = HTML's name attribute
  • ClientID = HTML's id attribute

Where the confusion comes from ? Probably from your respective favourite browsers. Indeed you will probably end by doing some JavaScript and so doing a getElementById. The only thing is that IE will be more permissive and will find your control if you do a getElementById(Element's name), but FireFox wil fail.

In a single word : ClientID = HTML's id attribute and so when doing getElementById, you should always give the ClientId.

Billets liés

Ajouter un commentaire


 

  Country flag





Live preview

décembre 2. 2008 15:14

Powered by BlogEngine.NET 1.2.0.0 | Theme by Pierre-Emmanuel Dautreppe