Hi!
I have the following in the head section of the .aspx file:
<script language="javascript" type="text/javascript">
function Validations()
{
if(document.getElementById("TxtboxTo").Value== "")
{
alert('Enter atleast one email ID');
document.getElementById("TxtboxTo").focus();
return false;
}
else if(document.getElementById("txtboxmessage").value == "")
{
alert('Please enter Password');
document.getElementById("txtboxmessage").focus();
return false;
}
else
{
return true;
}
}
And I am calling this javascript using onclientclick="return Validations();"
Also, I have onclick event for the button.
The problem, is that javascript function is not getting executed instead directly the onclick event is getting fired. I have tried onclientclick="return javascript:Validations();", onclientclick="javascript:Validations();", onclientclick=" Validations();", onclientclick=" Validations(); return;" etc., but nothing is working.
However, when I tried the following javascript:
function Check()
{
alert('Testin');
}
script>
and onclientclick="Check();", it is working perfectly.
Can anyone suggest me what I am doing wrong in Validations javascript?
How to make onclientclick and onclick both work so that only after javascript validations are complete to true then only onclick event gets fired.
Appreciate your quick response.
Thanks,
Mokshasri
Loading
MokshasriPosted Dec 7, 2009, 12:30 PM
Amit ChoudharyPosted Dec 7, 2009, 1:33 AM
First you have to remove the Server side fucntion call from the button..
now call that server side function from the javascript function like this...
<script type="text/javascript">
function SomeFunction() {
if(
{
// do some work
}
else
{
javascript: __doPostBack('btnSubmit','OnClick');
}
}
script>
if this is your answer then please mark it...
Kirtan PatelPosted Dec 6, 2009, 4:30 PM
OnClick and OnClientClick are same ...so you cant execute both.
so just Write Some IF Condition in OnClientClick event that your code executes after some other code :)