views:

252

answers:

1

Hi.

I have a RequiredFieldValidator with Display="Dynamic" on my ASP.NET WebForm. I have assigned it a class using the CssClass property. I want the error message to be displayed using display: block, so I have placed this on the css class in my style sheet.

Unfortunately, the validator places a display: inline on the element on the web page, effectivaly overriding my style sheet value.

Can I get rid of that?

Edit:

I just realised why this doesn't work. When setting Display="Dynamic" on a validator, it has the effect that it sets style="display: none" on the span tag when rendering. The .net javascript library then switches the inline style of the element between "none" and "inline". That is simply how the dynamic validator works. So for this to display as a block element, I will need to modify how the client side event validation works. Is it possible to do that?

A: 

Maybe this can help you:
http://caliberwebgroup.blogspot.com/2009/02/overriding-javascript-in-webresourceaxd.html

Pieter Nijs
That doesn't work. It simply has the effect that the validator is shown when the page loads (which is not what I want). When I try to sumbit, it changes the style back to "inline" (if validation fails). See my edited post for the reason why this happens.
Pete
Ok, wasn't paying much attention! I updated my post, maybe that can help!
Pieter Nijs
Hey. Thanks for the update. It's not the prettiest solution because it globally affects all validators, and it's dependent on stuff that's implementation details of the .NET framework. But it works (gives the desired result). Though a prettier solution could be to change between toggle a CSS class. That way you at least have the option of deciding on a pr. validator basis if it should be block or inline.
Pete