You can use a Literal
control and set it to PassThrough
mode. This is the easiest way for the hr
tag
Literal myTag = new Literal {Mode = LiteralMode.PassThrough, Text = "<hr/>"};
You can find more information here
If you are creating an h1
tag then you should use this
HtmlContainerControl myTag = (HtmlContainerControl)new HtmlGenericControl("h1");
This will allow you to add controls to the contents of the tag.
You shouldn’t use the standard HtmlGenericControl
for the hr
tag because the implementation doesn’t allow tag self-closing. The hr
tag would be written as <hr></hr>
instead of <hr/>
. But you can make it self closing with a little work, by overriding the control. See here for details
solved How to write out an hr tag programatically in .net [closed]