473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

embedding CRLF

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();
Jul 26 '07 #1
2 4057
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

"John Grandy" wrote:
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();
Jul 26 '07 #2
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 <spanwith 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";

"Peter Bromberg [C# MVP]" <pb*******@yahoo.yohohhoandabottleofrum.comwrote
in message news:56**********************************@microsof t.com...
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

"John Grandy" wrote:
>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();

Jul 26 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alicia Haumann | last post by:
I accidentally sent this to webmaster@python.org, so this could be a duplicate if "webmaster" forwards it to this list. :{ Hi, there. Thanks for any help that can be offered. I've been...
12
by: eddie wang | last post by:
What is CRLF? Thanks. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
4
by: McKirahan | last post by:
How would I use a regular expression to remove all trailing Carriage Returns and Line Feeds (%0D%0A) from a textarea's value? Thanks in advance. Also, are they any great references for learning...
5
by: McKirahan | last post by:
I'd like to use regular expressions to remove extraneous Carriage Return Line Feeds (CrLf) from a textarea before the form is submitted. I'd like to remove all trailing CrLf's and convert all...
3
by: Jon | last post by:
Hi... I'm getting stumped over the something that MUST be simple...basically, I'm trying to replace the characters 0D0A with a crlf, using Regex.Replace(). The problem is, the replaced string...
1
by: Jack Wright | last post by:
Dear All, In a multiline field if I enter the following way: Mangesh Anant Kodilkar There is a carriage return after each word. Now when I press save,it loses the CRLF characters. This is not...
2
by: Michael Persaud | last post by:
Hi All, Im trying to have a few strings presented in a LABEL. However the CRLF is not working. eg str = str1 + crlf + str2 + crlf + str3 label.text= str Do i need to declare the crlf as a...
2
by: Andrew | last post by:
Hello. I am working with very large files in my .NET project (1 million plus records). Some of these files do not have crlf's, which makes it very hard to read the file without a layout or record...
0
by: Tomas | last post by:
When I use a __doPostBack to submit a page to the server the last textbox on the page always contains a CRLF. I've used HttpRequest.SaveAs to dump the entire request (IIS 6) to disk and the body of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.