Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET control to render a <div>

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?

like image 530
James Avatar asked Apr 15 '11 09:04

James


1 Answers

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> 

It's a container, so you add Controls to it in the code-behind like:

myPanel.Controls.Add(new LiteralControl("Hello World")); 

You can add the Literal control (or any others) in the markup if you like and just assign to its Text property if you want it to update dynamically at runtime.

like image 126
Matías Fidemraizer Avatar answered Oct 11 '22 15:10

Matías Fidemraizer