ASP.NET control to render a <div>

James picture James · Apr 15, 2011 · Viewed 79.9k times · Source

The Label control in ASP.NET seems to render <span> tags, but is there a server control to render HTML within a <div>?

Sure, I could set display: block and it might look the same, but I'd rather not be nesting divs inside spans. Also I'd prefer not to use <%= MyVariable %> because that might not behave nicely on postbacks.

Any suggestions, please?

Answer

Mat&#237;as Fidemraizer picture Matías Fidemraizer · Apr 15, 2011

Of course: ASP.NET has a built-in control called Panel!

And you may use it as follows:

<asp:Panel ID="myPanel" runat="server">
    <!-- Other markup here like client and server controls/elements -->
</asp:Panel>