When attempting to create a lengthy RegEx ErrorMessage via server controls, I though it would be a nice add a background color and boarder to give the message some "flair".
When I tried attaching a CssClassto the server control with a border and color, the border ran over across two lines like below:
______________________________________
| |
| --------------------------- |
| | My very long error message | <-- confined box where error
| ---------------------------- | messages and text-box for input
| ---------------------------- | resides
| that ran over two lines | |
| --------------------------- |
| |
| ^ |
| | The two line error |
| message |
|_____________________________________|
<asp:RegularExpressionValidator
ID="MyFirstRegex"
ControlToValidate="SomeControl"
runat="server">
Display="Dynamic"
CssClass="SomeClass"
ValidationGroup="MyGroup"
ErrorMessage="Silly User. <br\> You made a very, very, very, very, very dumb error"<br />"
ValidationExpression="regex code to validate"
</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator
ID="ReqOne"
ValidationGroup="MyGroup"
ControlToValidate="SomeControl"
runat="server">
</asp:RequiredFieldValidator>
Also, when it hides, the boarder is visible (just not the contents)
I have tried placing the control in a div with run at server. The issue with that is when you hide the div, the regex validation stops. Any ideas on how to approach this?
Normally you set Validators to
Display="Dynamic". This ensures they do not take us space until they are triggered by a button. This is done by aspnet by addingstyle="display:none;"to the<span>element containing the error message.Now when the validator is triggered the style is changed from
display:nonetodisplay: inline.And it is with the
inlinepart that causes all the problems. We want it to be a normalblock. To do that you can override a javascript function that normally is located in theScriptResource.axdfile. That function is calledValidatorUpdateDisplay, and is has a line which containsval.style.display = val.isvalid ? "none" : "inline";. That is the line that needs to be overridden.