label formatting

IxiRancid

Centurion
Joined
Jun 16, 2004
Messages
104
Location
Europe
I started learning PHP and found some quite good functionality.
I'm pretty experienced in VB.NET, now really pushing hard on ASP.NET

One of PHP's tricks I like is that I can modify a string with HTML and display it like so #echo("<b>how kewl!</b>")# and formatting gets bold.
Could this be done in asp.net label?
I know it's a response.write thing, but I can't control the relative HTML position of this response.write... do I? :confused:
 
You can't really control where Response.Write ends up, but you can give an element in your ASPX page an ID and a runat="server" so that you can manipulate it in code (ideally code behind).

So as kahlua001 suggests, in your ASPX you might have (an asp.net label control inside an html paragraph element):

Code:
<p><asp:label id="lblWhatever" runat="server"></p>

An asp:label control is just an html span that's encapsulated as an object for ease of coding. It allows you to richly manipulate it via .Net code, but ultimately ASP.NET rendars an asp:label as an html span tag with appropriate attributes and styles based on how you've manipulated it in code.

In your code it'd be declared in the appropriate section as:

[csharp]protected System.Web.UI.WebControls.Label lblWhatever;[/csharp]

Which would then enable you to bold using Kahlua001's suggestion or to do it more manually with:

[csharp]lblWhatever.Text = "<b>ASP.NET is fun!</b>";[/csharp]

Paul
 
Ok, now this is strange...
I just did a simple Label1.Text = "<b>Nice</b> stuff" and it perfectly formatted Nice in bold...
I just have to figure out when or where have I tried this but didn't work! :confused:

Thanks to both!
 
Back
Top