问题描述
在ASP.NET Label控件似乎呈现<跨度>
标签,但有一个服务器控件中的&LT渲染HTML ; DIV>
The Label control in ASP.NET seems to render <span>
tags, but is there a server control to render HTML within a <div>
?
当然,我可以设置显示:块
,它可能看起来是一样的,但我宁愿不div的嵌套里面跨越。此外,我倒是preFER不使用&LT;%= MyVariable的%&GT;
,因为这可能不是很好的回发的行为
Sure, I could set display: block
and it might look the same, but I'd rather not be nesting divs inside spans. Also I'd prefer not to use <%= MyVariable %>
because that might not behave nicely on postbacks.
任何建议,请?
推荐答案
我认为你需要<$c$c>HtmlGenericControl$c$c>类。它有它接受一个字符串变量,它初始化的新实例构造的 HtmlGenericControl
类与指定的标记:
I think you need HtmlGenericControl
class. It has a constructor which accepts a string variable which initializes a new instance of the HtmlGenericControl
class with the specified tag:
var div = new HtmlGenericControl("div");
也有的innerHTML
和的InnerText
属性(你在注释中的previous提到了这一点答案)。
It is also has InnerHtml
and InnerText
properties (you mentioned this in a comment to the previous answer).
这篇关于ASP.NET控件呈现一个&LT; DIV&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!