IxiRancid Posted May 19, 2005 Posted May 19, 2005 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: Quote
PWNettle Posted May 19, 2005 Posted May 19, 2005 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): <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 Quote
IxiRancid Posted May 20, 2005 Author Posted May 20, 2005 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! Quote
Administrators PlausiblyDamp Posted May 20, 2005 Administrators Posted May 20, 2005 Easier way is just to use a Literal control rather than a label. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.