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?
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);
}
try to use tag
<br>
instead of Environment.NewLine
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.