3

Consider this code below:

<asp:RegularExpressionValidator 
        ID="MyTestId"  
        ValidationGroup="MyTestGroup" 
        ErrorMessage="You are a silly user. You entered the wrong format for this problem. Please try again. Using this format! ELRLDKX##Z"
        ValidationExpression="some unrelated regex"
        runat="server"
        ControlToValidate="MyTestTextbox">
</asp:RegularExpressionValidator> 

Is there a way to insert an escape character of some sort into the ErrorMessage string to ensure that Please try again. Using this format! ELRLDKX##Z is on another line? I have tried, \n with no luck.

VDWWD
  • 35,079
  • 22
  • 62
  • 79

1 Answers1

4

The Validator is on a web page, so you can just add html code to the text, like a <br />

ErrorMessage="You are a silly user. You entered the wrong format for this problem.<br />Please try again. Using this format! ELRLDKX##Z"
VDWWD
  • 35,079
  • 22
  • 62
  • 79
  • This works well, however, another issue that I have run into is that the boarder I have for the error message runs onto two lines when I use it. Any fixes for that? – pointedPenguin Mar 29 '17 at 20:44
  • Sorry, I don't quite understand what you mean by that... But Validators have a `Display` property, maybe setting it to `dynamic` can help? – VDWWD Mar 29 '17 at 20:59
  • So, I set the display to dynamic. I then wanted to give my validators some "flair" with a boarder and background color. What happened was I get something along the lines of: --------------------------- | You are a silly user -------------------------- You entered the wrong format........| -------------------------------------------- – pointedPenguin Mar 29 '17 at 22:12
  • where the boarders are running over to the next line. I tried using div with a run at server, however, the issue is that hiding the div causes the control to turn off. – pointedPenguin Mar 29 '17 at 22:19
  • background-color:red; text-align:left; text-wrap:normal; border:solid; display:block; color:black; margin-bottom:10px; padding:2px; – pointedPenguin Mar 30 '17 at 14:50