How to call javascript function with Validators?

goodmorningsky

Centurion
Joined
Aug 18, 2003
Messages
172
Hi, all. I got stuck...here..
Let me simplify my problem..

I added One TextBox, and Required Validator associated with the textbox.
And, Submit button.

When submit is clicked it should do some thing before submit.
So, when button clicked javascript function "SaveData()" must be called.

So, I added following code to Page_Load event.

this.btSubmit.Attributes.Add("onclick","return SaveData() ;") ;

After adding this, validator doesn't work! Event with empty textbox, it still submit to server without stopping..

SaveData() is this.
<script language="javascript">
<!--
function SaveData()
{
if (!true)
return false ;
try{
//do nothing
}catch(e){}
return true ;
}
-->
</script>

and the client side code generated is following.

<input type="submit" name="Button1" value="Button" onclick="return SaveData() ;if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); " language="javascript" id="Button1" />

It seems validator doesn't work if there is javascript function call.
How can I do both, calling javascript code and using validator?

Any comment will help!
Thank you.
 
Back
Top