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.
精彩评论