Validators ok, but code still runs

  • Thread starter Thread starter Pete Baugh
  • Start date Start date
P

Pete Baugh

Hi Folks,
I've got a simple aspx page with a few input controls on with required
fieldvalidators for each and a submit button. The validators work fine
when I click the button without having entered any of the fields.

However, after having added some code behind for the buttons _Click
event to save the data in the database, I have discovered that the
code will run anyway. So on a click, the validators fire up and
correctly display that the fields have not been filled but then the
code runs and saves the blank entry to the database.

Have I missed something somewhere?? I have an example of a similar
situation from some Wrox code, and I can't see any further check in
the code behind....

Any help gratefully received...

Many Thanks,
Pete Baugh
(e-mail address removed)
 
Hi Pete,

It is a strange behavior that can be caused by many things.
Check your Submit button properties under CausesValidation and make sure it
is set to true.
Check your Document(Form) properties and make sure its EnableViewState is
set to true and DefaultCLientScript is set to JScript.
Also check the events of your required fieldvalidators to make sure they are
not associated to an event launch.

Let me know how this works

Patrick
 
Pete:

It sounds like the example code doesn't have a check of the IsValid
property (a Page property) in the event handler. On the server side,
everything executes normally and it's up to the developer to check
IsValid and alter the normal flow of logic.

HTH,
 
Thanks for that,
Actually after I posted that I did put in a 'if (isvalid)' check and
the code now works fine (hurrah!). Th only thing that I'm still
scratching my head about is that the WROX example code doesn't mention
isvalid anywhere... and it seems to work fine. Oh well, on to the next
frustrating issue!!

Thanks very much guys,

Peter Baugh
 
Back
Top