ValidatorOnSubmit - Client Side Validation

G

Guest

For client side validation, the following code is generated by the framework
<form name="Form1" method="post" onsubmit=" if (!ValidatorOnSubmit()) return
false; MyFunction...">


My Problem is that, I need to call another javascript function regardless of
whether or not ValidatorOnSubmit() is true or false (i.e client side
validation fails or passes). My WebUIValidation.js has
function ValidatorCommonOnSubmit() {
var result = !Page_BlockSubmit;
Page_BlockSubmit = false;
event.returnValue = result;
return result;
}
But still my form has onsubmit = "if (!ValidatorOnSubmit()) return false;
MyFunction()"
Hence MyFunction() is not being called when the validation fails. I want it
to be called everytime.. how can I change this so that my function is also
called??
Any help will be appreciated..
 
G

Guest

You can use the method Page.RegisterOnSubmitStatement method for this e.g. in
Page_Load:

this.RegisterOnSubmitStatement("MyMethod", "MyMethod();");

The client-side call to MyMethod is then places before the call to
ValidatorOnSubmit in the onsubmit event for the form tag.

HTH, Jakob.
 
G

Guest

Try this...

var temp; if(!ValidatorOnSubmit()) temp = false; MyFunction(); if(temp ==
false) return temp;

Brad.
 
G

Guest

Thanks a million Jakob.. it works.. however, I wonder what is the difference
between RegisterStartUpScript and form.Attributes["OnSubmit"].
Earlier I was using the following code in Page_Load
if ( form.Attributes["onsubmit"] == null)
{
form.Attributes.Add("onsubmit", " " +"MyMethod()");
}
and it was placing the call after the validation script call.. strange.
Anyways It works now, just curious about the difference.. thanks much..
 

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,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top