Thursday, 4 December 2008

Label reference to non-existent ID

This can occur when you create a label tag to point to the ID of a text box.

<label for="email">Email address</label>
<asp:TextBox ID="email" Text="" runat="server"/>

But at render time ASP.NET changes the ID to something like ctl08_email

This can be rectified by replacing the following in the 'for' attribute.

<label for="<%= email.ClientID %>">


ASP.NET will now place the TextBox ID in the labels 'for' attribute.

1 comment:

Anonymous said...

Great post, very helpful :)