使用资源时,asp:label被转换为span元素 [英] asp:label gets converted as span element when resource is used
问题描述
我有一个标签元素,如下所示:
I have a label element as below:
<asp:Label ID="date" runat="server" Text="<%$ Resources:Resource, DATE%>" CssClass="col-sm-4 control-label" />
当我以某种方式在浏览器中渲染此图像时,它会生成以生成如下所示的span元素:
When I render this in the browser somehow this gets generated to span element as below:
<span id="ctl00_MainContent_FormDate_Date" class="col-sm-4 control-label">Date</span>
这使得它在页面上看起来与众不同.
which makes it look different on the page.
但是当我使用文本而不是资源时:
But when I use text instead of resource:
<asp:Label ID="date" runat="server" Text="Date" CssClass="col-sm-4 control-label" />
这可以正确呈现:
<label for="ctl00_MainContent_FormDate_Date" class="col-xs-4 control-label">Date</label>
任何人都可以解决此问题,在使用资源时如何解决该问题以呈现为< label>
?
Anyone come a cross this issue and how can I fix the issue to render as <label>
when using resources?
推荐答案
尽管我知道您已经有了解决方案,但我仍在为该帖子的未来读者提供解答.
如果您设置 Label.AssociatedControlID
值,它将成为 label
元素.如果未与控件关联,或者换句话说,它没有用作 label
元素,则它将成为 span
元素.
If you set the Label.AssociatedControlID
value it becomes a label
element.
If it is not associated to a control or in other words not being used as a label
element it becomes a span
element.
与控件无关的 label
被认为是错误的标记.因此,如果未将 label
控件分配给控件,则.NET会将其放置为 span
元素,而不是放置 label
.
A label
which is not associated with a control is considered as a bad mark up. Hence if the label
control is not assigned to a control, instead of placing a label
.NET places that as a span
element.
这篇关于使用资源时,asp:label被转换为span元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!