R
retsam
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?
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?