Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression Validator - display block rather than inline when dynamic

Tags:

asp.net

vb.net

Is there any way to make a RegularExpressionValidator render itself using display:block, instead of display:inline in its style attribute, when setting the Display property to "Display='Dynamic'"?

I have tried setting it in the stylesheet but this gets overwritten when it is rendered on the page.

Thanks

like image 744
Tom Avatar asked Oct 14 '10 08:10

Tom


4 Answers

The idea above on using a css with !Important was so close I could taste it. Using that idea and CSS attribute selectors I did it. I had to use the "contains" selector to get it working in FF, but now I have tested it in IE10, FF and Chrome and so far it is working. It is really simple. Here is a sample validator in my aspx page

<asp:RequiredFieldValidator runat="server" ID="rfvRequired" ErrorMessage="This is required.<br/>This is line 2" ControlToValidate="tbRequired" ValidationGroup="CommonAttributesValidationGroup" SetFocusOnError="True" CssClass="valerror" Display="Dynamic"></asp:RequiredFieldValidator>

Next I have a style for valerror.

span.valerror[style*="inline"]
{
    display:block !Important;
    background-color: Yellow;
    border: 1px solid #cccccc;
    font-size:.9em;
}

That is it. how it works: when the span changes the style from "display:none" to "display:inline" the attribute selector on the span kicks in and forces it to be a block. You just need to make ONE css entry like the one above and make sure you make each validator that class.

like image 90
David Avatar answered Nov 09 '22 19:11

David


Just wrap the validator in a div:

<div><asp:RegularExpressionValidator id="x" runat="server"></div>
like image 23
WIRN Avatar answered Nov 09 '22 20:11

WIRN


I've found the only way to have the control not take up space when it is hidden and also display block is to put a <br /> tag after each validator.

So initially we have this: enter image description here

Then if there is an error it looks like this: enter image description here

like image 3
The Muffin Man Avatar answered Nov 09 '22 19:11

The Muffin Man


How about using !important in the CSS class?

like image 3
Andy Avatar answered Nov 09 '22 21:11

Andy