HowTo: Control the rendered Html tag on your custom, composite server controls
1 min read
1 min read
public class MySrvControl : WebControl, INamingContainer
{
public MySrvControl() : base(HtmlTextWriterTag.Div)
{
...
}
...
}
public class MySrvControl : CompositeControlNote, you don't need the INamingContainer marker interface any more, because it's already done by the CompositeControl. The line "base(HtmlTextWriterTag.Div) however will give you a compiler error, since there is no constructor on the CompositeControl which is taking parameters. So to still provide the same rendering functionality, you simply add
{
public MySrvControl() : base(HtmlTextWriterTag.Div)
{
...
}
...
}
public class MySrvControl : CompositeControl
{
public MySrvControl()
{
...
}
protected override HtmlTextWriterTag TagKey
{
get
{
return HtmlTextWriterTag.Div;
}
}
...
}