Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / July 2007

Tip: Looking for answers? Try searching our database.

embedding CRLF

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Grandy - 26 Jul 2007 01:50 GMT
I am not having success embedding carriage return and line feed characters
into a string and displaying them with an ASP.NET label.  Is anyone getting
either of the following to work ?

StringBuilder message = new StringBuilder();
message.Append("Line 1");
message.Append("\r\n");
message.Append("Line 2");
Label.Text = message.ToString();

StringBuilder message = new StringBuilder();
message.Append("Line 1");
message.AppendLine();
message.Append("Line 2");
Label.Text = message.ToString();
Peter Bromberg [C# MVP] - 26 Jul 2007 02:02 GMT
First, this is really not a C# language group question and should probably
have been directed to the ASP.NET newsgroup instead.

ASP.NET Label control will display HTML. "\r\n" is not html -- <BR/> is.
Try that.

-- Peter
Recursion: see Recursion
site:  http://www.eggheadcafe.com
unBlog:  http://petesbloggerama.blogspot.com
bogMetaFinder:    http://www.blogmetafinder.com

> I am not having success embedding carriage return and line feed characters
> into a string and displaying them with an ASP.NET label.  Is anyone getting
[quoted text clipped - 11 lines]
> message.Append("Line 2");
> Label.Text = message.ToString();
John Grandy - 26 Jul 2007 19:09 GMT
Yeah, wrong forum, whatever.

There's actually a decent reason why I thought \r\n would work.

The ASP.NET Label control performs magic behind the scenes, such as HTML
encoding, to ensure that content shows up right.

However, directly embedding <br/> doesn't work , because ASP.NET renders the
Label control as a <span> with literal content

&lt;br/&gt;

which will show on the web page as

<br/>

And of course performing the HTML encoding yourself makes matters even worse

Server.HMTLEncode("<br/>") is rendered as

amp;lt;br/amp;gt;

I was thinking the ASP.NET Label control would be smart enough to recognize
\r\n and render it as <br/>  ... nope.  I don't think an ASP.NET Label
control is capable of rendering the line breaks.

However, you can use a server-side span element ...

.aspx
<span id="span1" runat="server">

.aspx.cs
HtmlGenericControl span1;
span1.InnerHtml = "blah blah blah <br/> blah blah blah";

> First, this is really not a C# language group question and should probably
> have been directed to the ASP.NET newsgroup instead.
[quoted text clipped - 25 lines]
>> message.Append("Line 2");
>> Label.Text = message.ToString();

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.