问题描述
限时送ChatGPT账号..当我创建表单时,我尝试将可访问性放在首位,但是 asp .NET 的输出否定了其中的一些.例如,当我为输入标签设置标签标签时,我将其创建为:
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" />
但是,当HTML从页面输出时,输出为:
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" />
这是一个问题,因为现在标签不再绑定到输入元素.有没有办法强制 .NET 输出我为输入字段设置的 exact id?我不应该使用 Javascript 来纠正这样的事情.
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.
推荐答案
使用 asp:Label
元素并将其 AssociatedControlId
属性指向您的文本框.
Use the asp:Label
element and point its AssociatedControlId
property to your textbox.
<asp:Label ID="lblFirstName" runat="server" AssociatedControlId="frmFirstName">First Name<span class="required">*</span></asp:Label>
<asp:TextBox id="frmFirstName" CssClass="textbox" runat="server" />
这应该会为您输出正确的 HTML.
That should output the correct HTML for you.
这篇关于有没有一种方法可以在输出到 HTML 时保留我为 asp 控件设置的 id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论