Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to force a WebControl to render as a <div> instead of a <span>?

How can I force the WebControl to render as a <div>? Currently, it renders as a <span> and our UI guy prefers it be a <div>. To accommodate him, I'd like to see if this is possible and if so, how it's possible.

like image 380
Yatrix Avatar asked Dec 21 '22 18:12

Yatrix


2 Answers

You can override the RenderBeginTag method of WebControl:

public override void RenderBeginTag(HtmlTextWriter writer)
{
    writer.RenderBeginTag("div");
}

There's also a RenderEndTag that you can override, which might not be necessary in this case:

public override void RenderEndTag(HtmlTextWriter writer)
{
    writer.RenderBeginTag();
}
like image 190
Joe Blazek Avatar answered Jan 04 '23 22:01

Joe Blazek


Yes, it is definitely possible. Asp.net gives you full control over the output rendered.

Take a look at Control Adapters

The asp.net team has released many adapters for CSS friendly rendering for controls like Menu, TreeView, and FormView. Take a look at CSS friend control adapters

You can always build your own to customize the rendering as needed by your UI guy.

like image 37
nunespascal Avatar answered Jan 04 '23 23:01

nunespascal