Home All Groups Group Topic Archive Search About
Author
31 Mar 2005 4:07 PM
Louis Yeung
Hi,

I am playing with validators using VS2003 on a XP box. I have textboxes with
regExp validators and a button. The validators work when I press the button.
If any validator fails, error messages are displayed and button click event
does not fire (i.e. not hitting my breakpoint). Everything works as stated.
Some error messages are in line and some are shown in a validationSummary
control.

I added a customValidator to a textbox which already has a regExp 
validator. The custom validation code was fired. I set args.IsValid=false. I
was surprised the button click event was fired. Inside the event handler, I
examined the customValidator.IsValid and WebForm1.IsValid values which are
both false.

According to MSDN , the customValidator should behave like other validators.
Can someone explain why the button event is fired eventhough the
customValidator fails the validation.

...Louis

Author
31 Mar 2005 4:12 PM
Brock Allen
All server events fire, regardless of the outcome of Validation. In your
button handler, though, you should be checking Page.IsValid prior to making
assumptions about the data the user's provided. IOW, check Page.IsValid before
you use the data and save it to your database.

It sounds like you're using a CustomValidator without a client side validation
routine (which is fine). This is why your request made it to the server.
You can also provide a client side javascript validation function if that's
useful to you.

But again, you should always check IsValid in your event handlers since the
user can disbale javascript in the browser.

-Brock
DevelopMentor
http://staff.develop.com/ballen



Show quoteHide quote
> Hi,
>
> I am playing with validators using VS2003 on a XP box. I have
> textboxes with regExp validators and a button. The validators work
> when I press the button. If any validator fails, error messages are
> displayed and button click event does not fire (i.e. not hitting my
> breakpoint). Everything works as stated. Some error messages are in
> line and some are shown in a validationSummary control.
>
> I added a customValidator to a textbox which already has a regExp
> validator. The custom validation code was fired. I set
> args.IsValid=false. I was surprised the button click event was fired.
> Inside the event handler, I examined the customValidator.IsValid and
> WebForm1.IsValid values which are both false.
>
> According to MSDN , the customValidator should behave like other
> validators. Can someone explain why the button event is fired
> eventhough the customValidator fails the validation.
>
> ..Louis
>
Author
31 Mar 2005 4:57 PM
Louis Yeung
Brock,

I agree with you after I read another MSDN article. Why my button click
event did not fire when my regExp validator failed? I checked the displayed
page content and do not believe the regExp validator is running on client.

...Louis

Show quoteHide quote
"Brock Allen" wrote:

> All server events fire, regardless of the outcome of Validation. In your
> button handler, though, you should be checking Page.IsValid prior to making
> assumptions about the data the user's provided. IOW, check Page.IsValid before
> you use the data and save it to your database.
>
> It sounds like you're using a CustomValidator without a client side validation
> routine (which is fine). This is why your request made it to the server.
> You can also provide a client side javascript validation function if that's
> useful to you.
>
> But again, you should always check IsValid in your event handlers since the
> user can disbale javascript in the browser.
>
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>
>
> > Hi,
> >
> > I am playing with validators using VS2003 on a XP box. I have
> > textboxes with regExp validators and a button. The validators work
> > when I press the button. If any validator fails, error messages are
> > displayed and button click event does not fire (i.e. not hitting my
> > breakpoint). Everything works as stated. Some error messages are in
> > line and some are shown in a validationSummary control.
> >
> > I added a customValidator to a textbox which already has a regExp
> > validator. The custom validation code was fired. I set
> > args.IsValid=false. I was surprised the button click event was fired.
> > Inside the event handler, I examined the customValidator.IsValid and
> > WebForm1.IsValid values which are both false.
> >
> > According to MSDN , the customValidator should behave like other
> > validators. Can someone explain why the button event is fired
> > eventhough the customValidator fails the validation.
> >
> > ..Louis
> >
>
>
>
>
Author
31 Mar 2005 5:49 PM
Brock Allen
To disable the client-side script for testing purposes only, add ClientTarget="downlevel"
to your @Page directive and test it again to see if it really calls the button
click event:

<%@ Page ClientTarget="downlevel" ... %>

-Brock
DevelopMentor
http://staff.develop.com/ballen



Show quoteHide quote
> Brock,
>
> I agree with you after I read another MSDN article. Why my button
> click event did not fire when my regExp validator failed? I checked
> the displayed page content and do not believe the regExp validator is
> running on client.
>
> ..Louis
>
> "Brock Allen" wrote:
>
>> All server events fire, regardless of the outcome of Validation. In
>> your button handler, though, you should be checking Page.IsValid
>> prior to making assumptions about the data the user's provided. IOW,
>> check Page.IsValid before you use the data and save it to your
>> database.
>>
>> It sounds like you're using a CustomValidator without a client side
>> validation routine (which is fine). This is why your request made it
>> to the server. You can also provide a client side javascript
>> validation function if that's useful to you.
>>
>> But again, you should always check IsValid in your event handlers
>> since the user can disbale javascript in the browser.
>>
>> -Brock
>> DevelopMentor
>> http://staff.develop.com/ballen
>>> Hi,
>>>
>>> I am playing with validators using VS2003 on a XP box. I have
>>> textboxes with regExp validators and a button. The validators work
>>> when I press the button. If any validator fails, error messages are
>>> displayed and button click event does not fire (i.e. not hitting my
>>> breakpoint). Everything works as stated. Some error messages are in
>>> line and some are shown in a validationSummary control.
>>>
>>> I added a customValidator to a textbox which already has a regExp
>>> validator. The custom validation code was fired. I set
>>> args.IsValid=false. I was surprised the button click event was
>>> fired. Inside the event handler, I examined the
>>> customValidator.IsValid and WebForm1.IsValid values which are both
>>> false.
>>>
>>> According to MSDN , the customValidator should behave like other
>>> validators. Can someone explain why the button event is fired
>>> eventhough the customValidator fails the validation.
>>>
>>> ..Louis
>>>
Author
31 Mar 2005 5:51 PM
Peter Blum
The reason it behaves this way is that you didn't supply a client-side
validation function for your custom validator. Client-side validation
processes the regular expression validator and thinks the page is fine. It
then submits the page. At that point, server side validation is run and
calls all validators including your customvalidator. By design, this step
happens after Page_Load and just before calling your Click event handler
method. Inside your Click event handler you should *ALWAYS* check the state
of validation on Page.IsValid because Click is *always* called even if the
page is invalid.

--- Peter Blum
www.PeterBlum.com
Email: PLB***@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

Show quoteHide quote
"Louis Yeung" <Louis Ye***@discussions.microsoft.com> wrote in message
news:C78C17E3-F48B-4310-B059-4779C5B55893@microsoft.com...
> Brock,
>
> I agree with you after I read another MSDN article. Why my button click
> event did not fire when my regExp validator failed? I checked the
> displayed
> page content and do not believe the regExp validator is running on client.
>
> ..Louis
>
> "Brock Allen" wrote:
>
>> All server events fire, regardless of the outcome of Validation. In your
>> button handler, though, you should be checking Page.IsValid prior to
>> making
>> assumptions about the data the user's provided. IOW, check Page.IsValid
>> before
>> you use the data and save it to your database.
>>
>> It sounds like you're using a CustomValidator without a client side
>> validation
>> routine (which is fine). This is why your request made it to the server.
>> You can also provide a client side javascript validation function if
>> that's
>> useful to you.
>>
>> But again, you should always check IsValid in your event handlers since
>> the
>> user can disbale javascript in the browser.
>>
>> -Brock
>> DevelopMentor
>> http://staff.develop.com/ballen
>>
>>
>>
>> > Hi,
>> >
>> > I am playing with validators using VS2003 on a XP box. I have
>> > textboxes with regExp validators and a button. The validators work
>> > when I press the button. If any validator fails, error messages are
>> > displayed and button click event does not fire (i.e. not hitting my
>> > breakpoint). Everything works as stated. Some error messages are in
>> > line and some are shown in a validationSummary control.
>> >
>> > I added a customValidator to a textbox which already has a regExp
>> > validator. The custom validation code was fired. I set
>> > args.IsValid=false. I was surprised the button click event was fired.
>> > Inside the event handler, I examined the customValidator.IsValid and
>> > WebForm1.IsValid values which are both false.
>> >
>> > According to MSDN , the customValidator should behave like other
>> > validators. Can someone explain why the button event is fired
>> > eventhough the customValidator fails the validation.
>> >
>> > ..Louis
>> >
>>
>>
>>
>>