How to call javascript function with Validators?

S

Sky Kim

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.
 
B

Brock Allen

If you want to add javascript into the page you should work with the ASP.NET
page architecture by calling Page.RegisterOnSubmitStatement.
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top