473,386 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to call javascript function with Validators?

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.

Nov 19 '05 #1
1 1739
If you want to add javascript into the page you should work with the ASP.NET
page architecture by calling Page.RegisterOnSubmitStatement.

-Brock
DevelopMentor
http://staff.develop.com/ballen
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.

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
2
by: Dot net work | last post by:
Hello. Say I have a .net textbox that uses a .net regularexpressionvalidator. If the regular expression fails, is it possible to launch a small client side javascript function to do something,...
4
by: Ian Cox | last post by:
I have a web form that contains a Datagrid. This grid has a number of columns, one of which contains a text box and validator for that text box. Everything works fine, when I press the "Save"...
5
by: M | last post by:
Hi, it's possible to append a custom action to a client-side verification of a validation control ? I have a validator summary control that shows (automatically) a message box if the validation...
1
by: IkBenHet | last post by:
Hello, Currently I am using a large input form on a website that is based on ASP and JavaScript. Depending on the values that are filled in by the user the forms does a refresh and makes...
5
by: | last post by:
Hi all, Has anyone been able to write some custom javascript on the onclick event of submit button to do certain things like disable submit button, only submit form once etc. This was a breeze...
0
by: Paul | last post by:
Hi all, I have a fairly basic page with some text boxes, validators and submit buttons. I have "EnableClientScript" set to false for all the validators and "enableEventValidation" set to false...
3
by: daokfella | last post by:
It looks like this is now an embedded resource. So is it permanently hidden? In earlier versions of .Net, I made a simple change to the WebUiValidation.js so that the validation summary was...
1
by: Nathan Sokalski | last post by:
When writing a validator by inheriting from the BaseValidator class, you need to include a JavaScript function that takes one parameter (the span tag generated by the validator) and returns true or...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.