Custom Validator newbie question

M

MattB

Hi. I've looked at a couple of examples and I thought I had a handle on
this, but it's not working like I expected.

I created a custom validator on my form that (for now) only has a server
side check that performs a luhn check on a credit card number. I've created
the validator, and the server side code to check the card number. The
problem is, I can enter invalid numbers and the validator never seems to do
anything - the numbers are accepted like there's no problem.

In stepping through this in the debugger, I see my validation sub execute,
and args.IsValid evaluates to false, but then I see no indication of this on
the page, like the validator never hears back from the sub I created.

Any ideas what I've done wrong? Thanks!

Matt
 
T

Teemu Keiski

Hi,

in the logic that is dependable on the validator, do you check Page.IsValid
or validator.IsValid before letting that code run? You need to check that
manually at server-side to ensure that validion is enforced.
 
M

MattB

I don't check those, but the other validators on the page work fine. They
are not custom (regex, compare, required field).
So even if those work ok, would this make my custom validator not work?
Thanks!
 
T

Teemu Keiski

If those other validators use client-side validation (in IE they do by
default) they prevent the postback on error scenarios, so that already
prevents the server-side code from running (even if your custom validator
would be OK) as validation goes all-or-nothing with the page.

To be safe for other browsers than IE, you need to check Page.IsValid or
validator.IsValid (depending on your situation if you want to overcome the
whole-page validation limitation) always when you have validators on the
page. Also to turn the aspect, writing only server-side check wires the
validation only when postback happens, so with such validator client-side
checks won't happen so Page:IsValid is your only way (buolt-in validation
controls work only at server.side for non-IE browsers)

Just to say that there's also a good commercial validation product on the
market, Peter Blum's Professional Validation And More, if you might be in
need for such. http://www.peterblum.com/VAM/Home.aspx It overcomes many
limitations that built-in ASp.NET validation controls have.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top