Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP.NET 2.0 clientvalidationfunction Firing When it Shouldn't

Reply
Thread Tools

ASP.NET 2.0 clientvalidationfunction Firing When it Shouldn't

 
 
mwieder@gmail.com
Guest
Posts: n/a
 
      04-03-2006
I've got an ASP.NET form with a textbox and a customvalidator. The
form inherits from a base wizard class with back, next and cancel
buttons. The CausesValidation property of the Cancel button gets set
to false, yet the javascript clientvalidationfunction is firing when
the cancel button is hit. Running through the debugger, the
CausesValidation property is set to false on the Page_Load of the
derived form. Why is the clientside javascript firing even though
causesvalidation is false? How do I stop this?

 
Reply With Quote
 
 
 
 
sam
Guest
Posts: n/a
 
      04-03-2006
Hello,

Please do a view source and paste that buttons onclick code here so we
can be sure its doing client side validation. You will see a
Page_ClientValidate() call on the onclick if it is. Also overload
OnPreRender() and make sure CausesValidation is not changed. I'd like
to see that html mentioned above if you care to post it.

-sam

 
Reply With Quote
 
 
 
 
sam
Guest
Posts: n/a
 
      04-03-2006
It just occured to me to make sure you have CausesPostback of that
button set to false.

-sam

 
Reply With Quote
 
mwieder@gmail.com
Guest
Posts: n/a
 
      04-03-2006
Here is the relevant code form the 'view source':
<script language="javascript">
<!--
function OnPasswordValidate(source, arguments) {
arguments.IsValid = pwd1.value == pwd2.value;
}
// -->



<td colspan="2"><input name="_ctl_AuthPage:_ctl22:tbxPassword"
type="password" id="_ctl_AuthPage__ctl22_tbxPassword" tabindex="5"
class="TextBox" style="width:350px;" /></td>
<td align="right"><span id="_ctl_AuthPage__ctl22_pwdCustomValidator"
title="Password must contain at least 6 characters"
evaluationfunction="CustomValidatorEvaluateIsValid "
clientvalidationfunction="OnPasswordValidate"
style="color:Red;visibility:hidden;"><img align='absmiddle'
src='/proCube/images/err.gif'/></span></td>



<a id="_ctl_AuthPage__ctl22__btnCancel" style="MARGIN-LEFT: 10px"
class="Button" tabindex="204" direct="true"
href="javascript:__doPostBack('_ctl_AuthPage$_ctl2 2$_btnCancel','')">Cancel</a></td>

 
Reply With Quote
 
sam
Guest
Posts: n/a
 
      04-03-2006
----
<a id="_ctl_AuthPage__ctl22__btnCancel" style="MARGIN-LEFT: 10px"
class="Button" tabindex="204" direct="true"
href="javascript:__doPostBack('_ctl_AuthPage$_ctl2 2$_btnCancel','')">Cancel*</a></
----
Client side validation is not happening here. It is happening on the
server. Look closely and you should notice the form posting back when
you press 'Cancel'.

Try setting CausesPostBack to false and see if that fixes it.

-
Sam

 
Reply With Quote
 
mwieder@gmail.com
Guest
Posts: n/a
 
      04-04-2006
Client side validation is happening - when I hit the cancel button, it
never makes it back to the server - the OnPasswordValidate method is
executed and it short circuits the call back to the server. We do want
the cancel button to post back to the server, we just don't want the
client side validation function to execute on cancel.

 
Reply With Quote
 
mwieder@gmail.com
Guest
Posts: n/a
 
      04-04-2006
Here's more info. Setting it to not postback to the server doesn't
help - also the error message displayed is only exists in the cleint
side code, so I know it is hitting the client side validation. I put a
break point in the clientside validation method and it got hit as well.
The stack is:
__doPostBack
common_newPostback
Page_ClientValidate
ValidatorValidate
CustomValidatorEvaluateIsValid
OnPasswordValidate

How do I stop the client validation from happening here?

 
Reply With Quote
 
Ray Booysen
Guest
Posts: n/a
 
      04-04-2006
wrote:
> Here's more info. Setting it to not postback to the server doesn't
> help - also the error message displayed is only exists in the cleint
> side code, so I know it is hitting the client side validation. I put a
> break point in the clientside validation method and it got hit as well.
> The stack is:
> __doPostBack
> common_newPostback
> Page_ClientValidate
> ValidatorValidate
> CustomValidatorEvaluateIsValid
> OnPasswordValidate
>
> How do I stop the client validation from happening here?
>

You can set the CausesValidation property for the button to false.
 
Reply With Quote
 
mwieder@gmail.com
Guest
Posts: n/a
 
      04-04-2006
hm... quoting from my initial post:
"The CausesValidation property of the Cancel button gets set
to false,"

 
Reply With Quote
 
sam
Guest
Posts: n/a
 
      04-04-2006
This 'common_newPostback' - did you write that javascript? That's
where the problem is. ASP.Net 1.1 does not have any such function in
__doPostback. In regular asp.net, __doPostback basically just does a
form submit.

I'm afraid its your own client side javascript code that isn't doing
what you want. You'll have to see who rewrote __doPostBack and how to
fix it.

-Sam

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CustomValidator ClientValidationFunction OnServerValidate Confusion labogart@hotmail.com ASP .Net 0 11-18-2009 04:47 PM
ClientValidationFunction function for a custom validator inside a repeater (ASPNET) Radu Javascript 0 01-26-2007 05:12 PM
ASP.NET 2.0 clientvalidationfunction Firing When it Shouldn't mwieder@gmail.com ASP .Net 0 04-03-2006 08:07 PM
CustomValidator.ClientValidationFunction not virtual Oleg Ogurok ASP .Net 1 07-05-2005 04:45 PM
Properties of ClientValidationFunction's arguments argument Jon Davis ASP .Net 0 01-20-2004 03:21 PM



Advertisments