Home All Groups Group Topic Archive Search About

Using Validators as field labels

Author
24 Feb 2006 10:44 PM
Chris Davoli
Can I use Validators as field labels AND as error fields. As an example I've
got a field (label) named "Formula:". I want to use a validator instead of a
label for the label of the field. So I put "Formula:" in the text field of
the validator and also put "Formula:" in the error messsage, so that the text
would be black when the validator was not tripped, but would be red if there
was an error ie like for a required field.

It won't let me do this because it won't show up the black field (even
though its visible=true and black foreground.

Is there any way to use a validator as a field label and as an error messge?

--
Chris Davoli

Author
24 Feb 2006 11:43 PM
Phillip Williams
A validator renders as <span> object with its style set to highlight an error
message if one exists otherwise it is empty.  You cannot use it as a label if
there is no error message.

To achieve the effect that you described you might consider replacing the
validators with a JavaScript that verifies a regular expression and based on
the outcome of the test it changes the style of the label and its message.  I
did an example using this concept by changing the style of the TextBox based
on the outcome of verifying that the entry is a valid number.
http://www.webswapp.com/codesamples/aspnet20/textbox/default.aspx

Show quoteHide quote
"Chris Davoli" wrote:

> Can I use Validators as field labels AND as error fields. As an example I've
> got a field (label) named "Formula:". I want to use a validator instead of a
> label for the label of the field. So I put "Formula:" in the text field of
> the validator and also put "Formula:" in the error messsage, so that the text
> would be black when the validator was not tripped, but would be red if there
> was an error ie like for a required field.
>
> It won't let me do this because it won't show up the black field (even
> though its visible=true and black foreground.
>
> Is there any way to use a validator as a field label and as an error messge?
>
> --
> Chris Davoli
>
Author
25 Feb 2006 4:19 PM
Peter Blum
Hi Chris,

The ASP.NET validators are pretty limited in their feature set. Generally
you have to create hacks into their validators or create your own code to
achieve anything outside of the functionality they offer.

I just wanted to let you know that I have solved this problem in my
Professional Validation And More (http://www.peterblum.com/vam/home.aspx).
Its a complete replacement to the ASP.NET validators that includes 25
validators, numerous improvements in setting up the evaluation rules, and
numerous improvements in formatting.
Its easy to use my validators to change the style of the field label when
reporting an error.

Suppose you have my RequiredTextValidator. You would set its Display
property to None, to hide the error message. Then you would add the
controlID of the field name into the HiliteFields property. Finally, you
would setup a style sheet (either page specific or global to the app) that
supplies the look of that label when there is an error.

--- Peter Blum
www.PeterBlum.com
Email: PLB***@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

Show quoteHide quote
"Chris Davoli" <ChrisDav***@discussions.microsoft.com> wrote in message
news:4CF3537D-55B3-47CE-9887-97EF9EC265C1@microsoft.com...
> Can I use Validators as field labels AND as error fields. As an example
> I've
> got a field (label) named "Formula:". I want to use a validator instead of
> a
> label for the label of the field. So I put "Formula:" in the text field of
> the validator and also put "Formula:" in the error messsage, so that the
> text
> would be black when the validator was not tripped, but would be red if
> there
> was an error ie like for a required field.
>
> It won't let me do this because it won't show up the black field (even
> though its visible=true and black foreground.
>
> Is there any way to use a validator as a field label and as an error
> messge?
>
> --
> Chris Davoli
>