One of the thing that infuriates me about ASP .NET is that Microsoft has made it so difficult to get rid of the inline styles in the validator controls.
On every one, there is the style declaration: style="color:red;visibility:hidden".
I object to this because I like to control the way my page looks from an external CSS sheet, separating content from presentation as every developer knows he should. I don't really think it's any of ASP .NET's business what colour my Controls are displayed
in - I believe it should be used as a medium to create and manage content, not to make stuff pretty. The other thing I find annoying is that given the choice, I'd rather specify that validators used the CSS "display: none" rule, rather than "visiblilty: invisible"
This is because they still take up space on the page when they're invisible, and make my forms look unnaturally spaced out. A Control with 3 sorts of validator below it has a huge gap below it but a Control with just one validator has a smaller gap.
So, I've been trying for ages to use the Control Adapters to prevent the ASP .NET engine from rendering the inline styles. My ideal scenario would be to give the BaseValidator two additional properties. One would be the CssClass to use when the Control is
valid. This would probably (but wouldn't have to) be a rule like "display: none;" . The other would be a different CssClass to use when the Control is invalid. This would probably (but wouldn't have to) be a rule like "display: inline; color: red". Then, the
client side JavaScript used by the Controls would be adapted so that the CssClass could be changed dynamically depending on validity.
I'm sad to say that so far I have failed.
It turns out that it is a much harder thing to accomplish than adapting the other ASP .NET controls. This is mainly because all the properties and scripts that you need are buried deep in the .NET framework, many of them not being exposed at the same level
that I'm developing. I've gone round and around in circles and it's almost as though Microsoft doesn't want me to develop their validation controls. What I want to achieve is so simple, but doing it seems near impossible.
Has anybody else tried? Has anyone had any success? Does anybody else agree with me? Are there any plans to redesign the validators so that they are friendlier to web control adapters in the next release of .NET?
Any opinions, stories (of success or of woe) or suggestions are welcome.
Ben
asp .net control adapters validator controls validation style css color visibility display
I know it mixes code and style, but it's the best I've found so far if you have to work with the ASP validation controls. If you can, I would use Peter Blum's validation control library. It's more robust than Microsoft's:
I do agree that you should be able to define two separate CssClasses for the controls though. Currently I haven't found away to get the validation message to display as a block level element without adding another child element to the span which gets generated.
BenCh1
Member
54 Points
19 Posts
Adapting the validator controls....
Apr 03, 2007 05:52 PM|LINK
One of the thing that infuriates me about ASP .NET is that Microsoft has made it so difficult to get rid of the inline styles in the validator controls.
On every one, there is the style declaration: style="color:red;visibility:hidden".
I object to this because I like to control the way my page looks from an external CSS sheet, separating content from presentation as every developer knows he should. I don't really think it's any of ASP .NET's business what colour my Controls are displayed in - I believe it should be used as a medium to create and manage content, not to make stuff pretty. The other thing I find annoying is that given the choice, I'd rather specify that validators used the CSS "display: none" rule, rather than "visiblilty: invisible" This is because they still take up space on the page when they're invisible, and make my forms look unnaturally spaced out. A Control with 3 sorts of validator below it has a huge gap below it but a Control with just one validator has a smaller gap.
So, I've been trying for ages to use the Control Adapters to prevent the ASP .NET engine from rendering the inline styles. My ideal scenario would be to give the BaseValidator two additional properties. One would be the CssClass to use when the Control is valid. This would probably (but wouldn't have to) be a rule like "display: none;" . The other would be a different CssClass to use when the Control is invalid. This would probably (but wouldn't have to) be a rule like "display: inline; color: red". Then, the client side JavaScript used by the Controls would be adapted so that the CssClass could be changed dynamically depending on validity.
I'm sad to say that so far I have failed.
It turns out that it is a much harder thing to accomplish than adapting the other ASP .NET controls. This is mainly because all the properties and scripts that you need are buried deep in the .NET framework, many of them not being exposed at the same level that I'm developing. I've gone round and around in circles and it's almost as though Microsoft doesn't want me to develop their validation controls. What I want to achieve is so simple, but doing it seems near impossible.
Has anybody else tried? Has anyone had any success? Does anybody else agree with me? Are there any plans to redesign the validators so that they are friendlier to web control adapters in the next release of .NET?
Any opinions, stories (of success or of woe) or suggestions are welcome.
Ben
asp .net control adapters validator controls validation style css color visibility display
nicjohnson
Member
52 Points
11 Posts
Re: Adapting the validator controls....
Sep 17, 2007 04:10 PM|LINK
I'm in the same boat. Late to the party, but having all of the same troubles. (Dang you, inline styles!!!)
neps
Member
27 Points
17 Posts
Re: Adapting the validator controls....
Sep 23, 2007 04:11 AM|LINK
I hate those damn inline style too!
Isn't anyone from the ASP.net team aware of this? There *MUST* be a workaround for this, like a control adapter or something...
gbdarren
Member
13 Points
5 Posts
Re: Adapting the validator controls....
Oct 01, 2007 06:30 PM|LINK
I just found out you can override the "color:red" by using this code in the code-behind:
ValidationControl.ForeColor = System.Drawing.Color.Empty
I know it mixes code and style, but it's the best I've found so far if you have to work with the ASP validation controls. If you can, I would use Peter Blum's validation control library. It's more robust than Microsoft's:
http://www.peterblum.com/VAM/Home.aspx
validation color
gbdarren
Member
13 Points
5 Posts
Re: Adapting the validator controls....
Oct 01, 2007 06:33 PM|LINK
Also, you can get the control to use the CSS: "display:none" by setting the Display property of the validation control to "Dynamic":
<asp:RegularExpressionValidator ID="valTxtIncome" ControlToValidate="txtIncome"
ErrorMessage="Invalid Number" Display="Dynamic" CssClass="errorMsg"
ValidationExpression="^[0-9]*$" runat="server"/>
validation validator color display css
drgonjo
Member
18 Points
11 Posts
Re: Adapting the validator controls....
Feb 15, 2008 07:54 PM|LINK
You can actually override the inline red color rule in an external CSS using !important like this:
.validationError
{
margin-left: 5px;
padding: 1px;
color: #666666 !important;
background-color: #fffff2;
border-width: 1px;
border-style: dotted;
border-color: Red;
}
I do agree that you should be able to define two separate CssClasses for the controls though. Currently I haven't found away to get the validation message to display as a block level element without adding another child element to the span which gets generated.
charalambos
Member
2 Points
1 Post
Re: Adapting the validator controls....
Oct 03, 2008 01:02 PM|LINK
All of the above mentioned can be achieved with different attributes. You must set them for each validator control though.
Set CSS class
CssClass="validation-message"
Remove inline font color
ForeColor=""
display:none instead of visibility:hidden
Display="Dynamic"