开发者

Difference between HtmlGenericControl and TagBuilder

开发者 https://www.devze.com 2023-04-03 08:32 出处:网络
This is more or less the same as this question, Difference between HtmlTable and TagBuilder("table") and

This is more or less the same as this question, Difference between HtmlTable and TagBuilder("table") and Why use TagBuilder instead of StringBuilder?

but I want to know that we when you do not have a .Net class for an HTML tag开发者_JAVA技巧 (like iFrame) in System.Web.UI.WebControls and System.Web.UI.HtmlControls then what to use?

@Edit: Can somebody tell me the difference between TagBuilder and HtmlGenericControl ?


You can use the HtmlGenericControl to represent any element:

HtmlGenericControl iframe = new HtmlGenericControl("iframe");
iframe.Attributes["src"] = "http://guffa.com/";

Edit:

The main difference between a HtmlGenericControl and the TagBuilder is that the control is made to work in a control hieararchy that you use to build the page, while the tag builder is only used to create the HTML code for a single tag. The control can for example have child controls, while you add child tags in a tag builder by first rendering them as strings and put them in the InnerHtml property.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号