Client Side validation and Post to method in CodeBehind Class

  • Thread starter Thread starter Gary Vidal
  • Start date Start date
G

Gary Vidal

I have a client side Javascript which checks an OrderQuantityField against a hidden Textbox of the Minimum Order Quantity. I dont want to do validation on a postback. I would like to be able to have FormValidate Javascript function postback to my addToCart Method in my code behind

function ValidateForm(myform) {
if (myform.OrderQuantity.value == 0) {
alert("Form is Invalid = 0 " + myform.OrderQuantity.value); return false
}
if (parseInt(myform.OrderQuantity.value,10) >= parseInt(myform.MinQuantity_Hidden.value,10)) {
}
else { alert("Order Quantity must be greater than " + myform.MinQuantity_Hidden);
myform.OrderQuantity.focus() return false
}
if (parseInt(myform.OrderQuantity.value,10) % parseInt(myform.MinQuantity_Hidden.value,10))
{ alert("Order Quantity must be in multiples of " + myform.MinQuantity_Hidden.value);

myform.OrderQuantity.focus()
return false
}
//Some code here to post back to the server method??

return true
}
 
It looks like you'd be happy with the Microsoft validator controls if they
only supported alert box messages and setting focus to the field with the
error. While that's not available with all that custom code you've been
writing, there is a commercial solution. My "Professional Validation And
More" (http://www.peterblum.com/vam/home.aspx) provides the ability to set
focus to the field with error, show an alert, change the color of the field
with the error or its label and even blink the error message. You will be
able to use it like Microsoft's validators, simply by dropping a validator
control onto the web form and set properties. There are 22 validators
included so many cases are available that would require custom coding in
Microsoft's system. I hope this helps.

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

Have you had a chance to try out all the suggestions in the former replies
or have you got any further ideas on this issue?
If you have any questions or need any assitance, please feel free to post
here.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Back
Top