ASP.NET控件呈现一个< D​​IV>控件、NET、ASP、GT

2023-09-03 05:40:25 作者:余生请多指教

在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.

任何建议,请?

推荐答案

我认为你需要HtmlGenericControl类。它有它接受一个字符串变量,它初始化的新实例构造的 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).

 
精彩推荐
图片推荐