Code not triggering

J

John

Hi

On my webform, in design mode when I double click on the button component,
it creates a click sub for me. But when I add code to the click event and
run the web form the code does not seem to be executed. I have verified this
by setting break points. Why would clicking the button not execute the click
sub in this case?

Thanks

Regards
 
O

OYTUN ASKIN

Do you have some sort of a validator object on any of the fields? If so and
your validator is triggered, then the code will not work.
 
J

John

This is a required valuator. What should I do to validate the field and
process the entries if the validation is fine?

Thanks

Regards
 
P

Peter Blum

I'm in disagreement with Oytun's reply and wanted to offer my help.

Validators do not block a button's Click event from running. The Click event
is always fired if its correctly setup.

Here's how validators work with buttons:
1. When the CausesValidation property is true (which is the default), it
internally calls Page.Validate() for you.
2. In your Click event, it is your responsibility to check Page.IsValid
before attempting to use the data.

In my experience, here's what causes a Click event not to fire:
1. It is not hooked up correctly.
2. Client-side validators are setup. When you submit, they prevent
submitting for various reasons and you never get a post back. Without a post
back, no server side code runs, including your Click event.
If you think that the page is valid but it does not post back, you may have
a buggy version of ASP.NET's validation. There is a problematic release in
the 1.1 series of releases. I haven't had this problem myself but have seen
many users with it and they have either found a hot fix on
msdn.microsoft.com or removed a hot fix. So it may be due to a particular
hot fix.

To test this, turn off client side validation by setting
EnableClientScript=false on each validator. Now no client-side code will
interfere with post back.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top