When I create a form, I try to make accessibility a top priority, but the output from asp .NET negates some of this. For example, when I set a label tag for an input tag, I create it a such:
<label for="frmFirstName">First Name<span class="required">*</span></label>
<asp:TextBox id="frmFirstName" CssClass="textbox" runat="server" />
But, when the HTML is output from the page, it is output as:
<label for="frmFirstName">First Name<span class="required">*</span></label>
<input name="ctl00$phMainContent$frmFirstName" type="text" id="ctl00_phMainContent_frmFirstName" class="textbox" />
This is a problem, as now the label is no longer tied to the input element. Is there a way to force .NET to output the exact id I set for the input field? I shouldn't have to use Javascript to correct something like this.
The label control is used to display a text or a message to the user on the form. The label control is normally used along with other controls.
The runat=”server” attribute is necessary for HTML control to work as a HTML server control.
The control ID is the unique ID of the control within the parent view. You can use the control ID to access a subview instance at run time.
If you use ASP.Net 4 you can set the ClientIDMode attribute of the control to static
. This will let it keep the value of the ID tag when rendered.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With