Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP.NET (Non-Forum Related)
 How to call javascript function with Validators?
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

GoodMorningSky
Junior Member

122 Posts

Posted - 18 April 2005 :  17:04:58  Show Profile
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.

Software Engineer.
MCSD.NET, SCWCD

GoodMorningSky
Junior Member

122 Posts

Posted - 19 April 2005 :  12:34:56  Show Profile
I solved by following code.

this.btSumit.Attributes.Add("onclick","if(!SaveData()){return false;}") ;

Software Engineer.
MCSD.NET, SCWCD
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000 Version 3.4.07