Reputation: 1442
I'm doing some server-side validation on a sharepoint aspx page. If there are any errors, I pass a string to the zone.error text in PreRender.
How do I get my newline characters to render?
Right now I have:
protected override void OnPreRender(EventArgs e)
{
if (!string.IsNullOrEmpty(_errorText))
{
this.Zone.ErrorText += "I'm an error!" + Environment.NewLine + "Fix me damnit!";
}
base.OnPreRender(e);
}
I have tried various combinations of
<br />, \r\n, \n, while using htmlEncode and htmlDecode to no avail.
I have read something about <pre>, in the past, but I'm not sure if this is the correct approach.
What's the trick here?
Upvotes: 2
Views: 1433
Reputation: 4072
You will need to render a <br/>
tag not an Environment.NewLine, that will simply drop a \n or \r\n in. That won't render on the HTML page.
protected override void OnPreRender(EventArgs e)
{
if (!string.IsNullOrEmpty(_errorText))
{
this.Zone.ErrorText += "I'm an error<br/>Fix me damnit!";
}
base.OnPreRender(e);
}
Upvotes: 4