Reputation: 46591
I have the following:
StringBuilder errors = new StringBuilder();
if(IsNullOrEmpty(value))
{
errors.AppendLine("Enter value");
}
if(IsNullOrEmpty(value2))
{
errors.AppendLine("Enter value 2");
}
I would expect this to display:
Enter value
Enter value 2
But it is displaying:
Enter value Enter value 2
I have also tried: AppendFormat("Enter value{0}",Environment.NewLine);
as well as with the \n
character.
The errors string is outputted to an asp:Label like:
lblErrors.Text = errors.ToString();
Upvotes: 1
Views: 3252
Reputation: 2435
in to string u can make as well errors.Append(Enviroment.NewLine);
@Brian in c# new line isn't "\n" "\r\n" is correct syntax of new line character:)
Upvotes: 0
Reputation: 41665
If you'd like to preserve all formatting (including tabs, consecutive white-space, etc), you can apply the white-space:pre style to your label or use an html pre element.
Upvotes: 1
Reputation: 1433
I would try to do something like
if(value.Empty == null){
errors.AppendLine("Enter Value");
}
By the code you are showing it seems like it doesn't go into the if statement.
Upvotes: 0
Reputation: 12596
As mentioned in some of the comments, HTML does not respect the new line character \n
. You need to use <br/>
instead.
Upvotes: 7