1. ホーム
  2. .net

[解決済み] ASP.NET control to render a <div>

2022-02-16 01:57:34

Question

The Label control in ASP.NET seems to render <span> tags, but is there a server control to render HTML within a <div> ?

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.

Any suggestions, please?

How to solved?

I think you need HtmlGenericControl class. It has a constructor which accepts a string variable which initializes a new instance of the HtmlGenericControl クラスは、指定されたタグで構成されています。

var div = new HtmlGenericControl("div");

また InnerHtmlInnerText プロパティを使用することができます(前回の回答へのコメントで言及されています)。