By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,960 Members | 990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,960 IT Pros & Developers. It's quick & easy.

Validators ok, but code still runs

P: n/a
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
pb****@recoilsoft.com
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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 Baugh" <pb****@recoilsoft.com> wrote in message
news:c6*************************@posting.google.co m...
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
pb****@recoilsoft.com

Nov 18 '05 #2

P: n/a
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,

--
Scott
http://www.OdeToCode.com

On 1 May 2004 02:31:51 -0700, pb****@recoilsoft.com (Pete Baugh)
wrote:
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
pb****@recoilsoft.com


Nov 18 '05 #3

P: n/a
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
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.