.NET FAQs Unleashed!
 
    
    

Which feature of ASP.NET 4.0 allows better control over the IDs of controls?

Before the advent of ASP.NET 4.0, IDs of controls used to look hefty after rendering, somewhat like this:

ctl00_ContentPlaceHolder1_ParentPanel_NamingPanel1_TextBox1

The new ClientIDMode property lets you specify more precisely how the client ID is generated for controls. You can set the ClientIDMode property for any control, including for the page. Possible settings are the following:

AutoID – This is equivalent to the algorithm for generating ClientID property values that was used in earlier versions of ASP.NET.

Static – This specifies that the ClientID value will be the same as the ID without concatenating the IDs of parent naming containers. This can be useful in Web user controls. Because a Web user control can be located on different pages and in different container controls, it can be difficult to write client script for controls that use the AutoID algorithm because you cannot predict what the ID values will be.

Predictable – This option is primarily for use in data controls that use repeating templates. It concatenates the ID properties of the control's naming containers, but generated ClientID values do not contain strings like "ctlxxx". This setting works in conjunction with the ClientIDRowSuffix property of the control. You set the ClientIDRowSuffix property to the name of a data field, and the value of that field is used as the suffix for the generated ClientID value. Typically you would use the primary key of a data record as the ClientIDRowSuffix value.

Inherit – This setting is the default behavior for controls; it specifies that a control's ID generation is the same as its parent.

ASP.NET 4 when IIS is reset   Meta Tags using the Page Directives   Response.Redirect(), Response.RedirectPermanent(), Server.Transfer()   Shrinking Session State   Expanding size of allowable URL   Preventing XSS Attacks in ASP.NET 4   New features in ASP.NET 4.0   Features of ASP.NET 4.0 Chart Control   Advantage of Response.RedirectPermanent()   Benefit of Extensible Output Caching   URL Routing   Web.config Refactoring   Controlling IDs of Controls   Monitor Performance in ASP.NET 4.0