Jump to content

Validation Controls

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
9 replies to this topic

#1
birko19

birko19

    Newbie

  • Members
  • PipPip
  • 27 posts
Ok, so I just discovered the power of the .NET enviourment in terms of validation, this of course saves me a lot of lines of code, but I have a question regarding displaying these validator controls on the form.

Let's say we have a field that requires two different validation methods, so let's say we have a text box for email, and this text box cannot be empty but at the same time it must be validated whether it's a proper email or not, so automaticly we will end up using two validation controls right here, one is the RequiredFieldValidator to validate whether the box is empty or not and the other one would be RegularExpressionValidator to validate if the email written is in proper email format or not, now the validation is the easy part once you set up these two controls, but my dillima here is that when I put the first validator next to the text box, and I put the other validator next to it, the error messages show up in different locations, the images below should explain the problem.

The following is when the person leaves the field blank:
Posted Image

And the following is when the person enters something, but it's not a proper email address:
Posted Image

Although the images are not that clear, you should notice in the second image that there's a small gap between the error message and the text box, that is because that gap is the place of the first validator (As you can see from image one), but since that validator does not need to be active at that moment, it's dissapearing and leaving a gap.

I would like to have both of these validators within the same location right next to the text box, and depending on the type of error, the error message should be in the same spot and not leave a gap, any ideas on how to do this?

Thank you :)

#2
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,671 posts
A typical solution is to add a validatiosummary control, and setting the text of the validators to *

#3
birko19

birko19

    Newbie

  • Members
  • PipPip
  • 27 posts
The problem with that solution is that it's a work around, not really a solution to the problem.

#4
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,671 posts
You are right, ive noticed that the regular expression didnt show up when the text box was empty, so why dont you just set both of the 2 validators to the same position

#5
birko19

birko19

    Newbie

  • Members
  • PipPip
  • 27 posts
I'll give it a try, I'm usually a code junky when it comes to validation so I'm getting a little too excited discovering these things ;)

#6
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,671 posts
Hehe
if it didnt work you can write a code to position the validators according to its state

#7
birko19

birko19

    Newbie

  • Members
  • PipPip
  • 27 posts
That worked like a charm, thanks amrosama.

All I had to do was change the position from "Not Set" to "Absolute", and what that allowed me to do is drag the one control which had the absolute setting and put it on top of the other control, pretty much placed it in the same position as the other, and it worked.

For those who are interested just in case you run into the same problem and you find this post, click on whatever control you want to change the position for, then click on "Layout", then "Position", then change it to "Absolute".

Once again, thank you :)

#8
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,671 posts
Glad i can help, iam eager to help codecall members as they have helped me over the past 2 years :-)

#9
birko19

birko19

    Newbie

  • Members
  • PipPip
  • 27 posts
Cheers to that mate :)

#10
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,671 posts
Cheers :D