HtmlGenericControl
-
Anybody know how to make the HtmlGenericControl output self-closing tags like instead of ? Should I set the InnerHtml or InnerText property to null or something like that?
-
Actually, I'd rather use HtmlGenericControl so I can programatically add element attributes and have to concatenate strings together... Can I achieve this with HtmlGenericControl by overriding the render method or something?
-
Hi there, You can use the LiteralControl[^] instead.
-
Actually, I'd rather use HtmlGenericControl so I can programatically add element attributes and have to concatenate strings together... Can I achieve this with HtmlGenericControl by overriding the render method or something?
Hi there, You can easily develop your own HtmlGenericControl by superclassing the
HtmlGenericControl
class in the .Net framework, the sample code looks something like:public class CustomHtmlGenericControl : System.Web.UI.HtmlControls.HtmlGenericControl
{
public CustomHtmlGenericControl(string tagName):base(tagName)
{
}public CustomHtmlGenericControl():base() { } protected override void Render(System.Web.UI.HtmlTextWriter writer) { writer.WriteBeginTag(this.TagName); this.RenderAttributes(writer); this.RenderChildren(writer); writer.Write("/>"); }
}
In addition, you can also override the
Render
method in the way that you first get the rendered html markup as normal, then simply replace the text></TagName>
with the/>
, and finally write out the result to the writer. -
Hi there, You can easily develop your own HtmlGenericControl by superclassing the
HtmlGenericControl
class in the .Net framework, the sample code looks something like:public class CustomHtmlGenericControl : System.Web.UI.HtmlControls.HtmlGenericControl
{
public CustomHtmlGenericControl(string tagName):base(tagName)
{
}public CustomHtmlGenericControl():base() { } protected override void Render(System.Web.UI.HtmlTextWriter writer) { writer.WriteBeginTag(this.TagName); this.RenderAttributes(writer); this.RenderChildren(writer); writer.Write("/>"); }
}
In addition, you can also override the
Render
method in the way that you first get the rendered html markup as normal, then simply replace the text></TagName>
with the/>
, and finally write out the result to the writer.