I have a generic html control – a ‘P’ tag, which i’ve added a runat="server" to.
I construct a string using Stringbuilder methods and apply this to the InnerHtml attribute of the tag.
The text,which contains a number of sb.Appendline()‘s still displays as a paragraph would, wrapping but without creating any new lines. However, When i look at the markup created, the new lines are there, shown as spacing.
This is also the case with a DIV
Anyone got any ideas as to how i fix this?
Code below:
var sb = new StringBuilder();
sb.Append("Congratulations!");
sb.AppendLine();
sb.AppendLine();
sb.AppendFormat("Your application was accepted by <b>{0}</b>.", response.AcceptedLender);
sb.AppendLine();
sb.AppendFormat("Your reference number is <b>{0}</b>.", response.PPDReference);
sb.AppendLine();
sb.AppendLine();
sb.Append("Click the button below to sign your loan agreement electronically and collect your cash.");
AcceptedMessage.InnerHtml = sb.ToString();
Instead of using
AppendLineshould useAppendFormat:If you need these line breaks to remain “as is” because you’re displaying it in a text file or something of that nature, you’ll need to replace the new line text with html breaks when you’re calling the
.ToString()method.Using
Environment.NewLinehere may not work, you may actually need to replace\r\n.