473,406 Members | 2,352 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,406 software developers and data experts.

How to build string with new lines and display on ASP.NET page.

All,
I'm working on an ASP.NET 2.0 (C#) page and have a question on how to build
a string that includes line feeds (new lines) that displays properly on an
ASP.NET page. Here's what I got:

..aspx page
<asp:Label ID="LabelMoreInformation" runat="server" Text=""></asp:Label>
code-behind for .aspx page
protected void Page_Load(object sender, EventArgs e)
{
string message = FormatMessage();

this.LabelMoreInformation.Text = message;
}

private string FormatMessage()
{
string message = "";
System.Text.StringBuilder sb = new System.Text.StringBuilder();

// Build the message
sb.Append(System.Environment.NewLine + System.Environment.NewLine);
sb.Append("Date/Time: " + System.DateTime.Now.ToString("g") +
System.Environment.NewLine);
sb.Append("System.Environment.MachineName: " +
System.Environment.MachineName + System.Environment.NewLine);

...

sb.Append(System.Environment.NewLine + System.Environment.NewLine);

message = sb.ToString();

return message;
}
The problem is that the text I put in the label does not have any line
breaks/new lines. The System.Environment.NewLine call doesn't seem to work
when I try to then display the string on an ASP.NET page. All the text is
run together.

So, how can I get line breaks/new lines for my string information in the
above scenario?
May 10 '06 #1
3 5753

"retsam" <no****@company.com> wrote in message
news:O1**************@TK2MSFTNGP04.phx.gbl...
All,
I'm working on an ASP.NET 2.0 (C#) page and have a question on how to build a string that includes line feeds (new lines) that displays properly on an
ASP.NET page. Here's what I got:

.aspx page
<asp:Label ID="LabelMoreInformation" runat="server" Text=""></asp:Label>
code-behind for .aspx page
protected void Page_Load(object sender, EventArgs e)
{
string message = FormatMessage();

this.LabelMoreInformation.Text = message;
}

private string FormatMessage()
{
string message = "";
System.Text.StringBuilder sb = new System.Text.StringBuilder();

// Build the message
sb.Append(System.Environment.NewLine + System.Environment.NewLine); sb.Append("Date/Time: " + System.DateTime.Now.ToString("g") +
System.Environment.NewLine);
sb.Append("System.Environment.MachineName: " +
System.Environment.MachineName + System.Environment.NewLine);

...

sb.Append(System.Environment.NewLine + System.Environment.NewLine);
message = sb.ToString();

return message;
}
The problem is that the text I put in the label does not have any line
breaks/new lines. The System.Environment.NewLine call doesn't seem to work when I try to then display the string on an ASP.NET page. All the text is
run together.

So, how can I get line breaks/new lines for my string information in the
above scenario?

Not to glamorous, but you could insert <br> to the string and it will result
in a carriage return.
Mike
May 10 '06 #2

TextBox has a multiline property somewhere.

Labels.... I think you gotta "<br/>" it like the previous post said.
You gotta remember there isn't such a thing as a Label or a TextBox on the
client side.
Its going to be rendered
<textarea> or other regular html controls.

Check your output (View Source) in the browser. Once you see how an
asp:label or asp:textbox gets rendered on the client, you'll better
understand your limitations.


"vMike" <Mi****************@noZorY.geZwaYrrenY.com> wrote in message
news:ye********************@comcast.com...

"retsam" <no****@company.com> wrote in message
news:O1**************@TK2MSFTNGP04.phx.gbl...
All,
I'm working on an ASP.NET 2.0 (C#) page and have a question on how to build
a string that includes line feeds (new lines) that displays properly on an ASP.NET page. Here's what I got:

.aspx page
<asp:Label ID="LabelMoreInformation" runat="server" Text=""></asp:Label>
code-behind for .aspx page
protected void Page_Load(object sender, EventArgs e)
{
string message = FormatMessage();

this.LabelMoreInformation.Text = message;
}

private string FormatMessage()
{
string message = "";
System.Text.StringBuilder sb = new System.Text.StringBuilder();

// Build the message
sb.Append(System.Environment.NewLine +

System.Environment.NewLine);
sb.Append("Date/Time: " + System.DateTime.Now.ToString("g") +
System.Environment.NewLine);
sb.Append("System.Environment.MachineName: " +
System.Environment.MachineName + System.Environment.NewLine);

...

sb.Append(System.Environment.NewLine +

System.Environment.NewLine);

message = sb.ToString();

return message;
}
The problem is that the text I put in the label does not have any line
breaks/new lines. The System.Environment.NewLine call doesn't seem to

work
when I try to then display the string on an ASP.NET page. All the text is run together.

So, how can I get line breaks/new lines for my string information in the
above scenario?

Not to glamorous, but you could insert <br> to the string and it will

result in a carriage return.
Mike

May 10 '06 #3
Thanks vMike! That worked. Before posting the message, I had tried <br />,
but that didn't work either--it was actually displaying <br />. I guess
taking the / out made it work.
Cheers

"vMike" <Mi****************@noZorY.geZwaYrrenY.com> wrote in message
news:ye********************@comcast.com...

"retsam" <no****@company.com> wrote in message
news:O1**************@TK2MSFTNGP04.phx.gbl...
All,
I'm working on an ASP.NET 2.0 (C#) page and have a question on how to build
a string that includes line feeds (new lines) that displays properly on an ASP.NET page. Here's what I got:

.aspx page
<asp:Label ID="LabelMoreInformation" runat="server" Text=""></asp:Label>
code-behind for .aspx page
protected void Page_Load(object sender, EventArgs e)
{
string message = FormatMessage();

this.LabelMoreInformation.Text = message;
}

private string FormatMessage()
{
string message = "";
System.Text.StringBuilder sb = new System.Text.StringBuilder();

// Build the message
sb.Append(System.Environment.NewLine +

System.Environment.NewLine);
sb.Append("Date/Time: " + System.DateTime.Now.ToString("g") +
System.Environment.NewLine);
sb.Append("System.Environment.MachineName: " +
System.Environment.MachineName + System.Environment.NewLine);

...

sb.Append(System.Environment.NewLine +

System.Environment.NewLine);

message = sb.ToString();

return message;
}
The problem is that the text I put in the label does not have any line
breaks/new lines. The System.Environment.NewLine call doesn't seem to

work
when I try to then display the string on an ASP.NET page. All the text is run together.

So, how can I get line breaks/new lines for my string information in the
above scenario?

Not to glamorous, but you could insert <br> to the string and it will

result in a carriage return.
Mike

May 10 '06 #4

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

Similar topics

10
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a...
6
by: Dave Reid | last post by:
Hi everyone... I'm pretty much a newbie C++ user, and I've run into a problem. I'm trying to read in a large text file, and then do manipulations on it. I can read it into a large 2-dimensional...
2
by: Jon | last post by:
Hi all, I am trying to create a page that contains a number of div elements, with links on the left side of the page allowing the user to select which div to display. Some of the pages contain...
3
by: Karsten Grombach | last post by:
How can I display the current build version of my webapplication at runtime? i.e. the version I set in my web deployment project. regards and thanks karsten
5
by: Bauer | last post by:
I am new to GDI+.I am drawing a string on the Win form using GDI+. My string content is long and it does not have any "vbcrlf". The whole string is displayed in a single line and is getting...
1
by: thuyptt | last post by:
Hi you!! I am programming a part of my application and I met a trouble in display test. I used fgets to read each line in a text file and display all lines on the screen. But the size of the...
1
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
6
by: Diffident | last post by:
Hi All, How can I prevent my end users from noticing an error when we are re-compiling our project? Is there any way? Or how can we show a user-friendly message when we are recompiling the...
0
by: ge0193387 | last post by:
I'm attempting to make a custom control that will let me drag drop images onto a web form and display the image in that same box. Any details on how to make that easier without turning me to a...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.