ASP.net 4.0 finally adds control of ClientIDs

Everyone, breathe a huge sigh of relief!

Tired of ASP.net mangling your ClientIDs when using Master Pages, to from a server-side ID of, say, EmployeeNameLabel, to something like ctl00_ContentPlaceHolder1_EmployeeNameLabel?  Sick of dealing with these silly (and ridiculously long) names in your JavaScript code?

Fortunately ASP.net 4.0 (VS2010) will allow you to change this behaviour with the new ClientIDMode property on controls.  You can set it per control.  The default behaviour is “Legacy“—the dog’s mangled breakfast—but you can change that to “Static“.  Doing so for my example label would cause it to render with a client-side ID of EmployeeNameLabel.  Static, FTW!

More details and pretty code here

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Scott’s recent tweets…


%d bloggers like this: