Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Return false is not working in JavaScript

Reply
Thread Tools

Return false is not working in JavaScript

 
 
=?Utf-8?B?c3Jpbml2YXM=?=
Guest
Posts: n/a
 
      02-07-2007
Hi,
I'm having an ASP.net page with a dropdown list box named ddlStatus, a
button and editable gridview.
I wrote a small javascript function "OnSave()" and called it on the event
'onClientClick()' event of the button.
I have a required field validator for the text boxes in the grid view also.
The dropdown list box contains 2 values 'Open' Or 'Close'.
If the user clicks the Button by selecting the 'Close' then i have to
display a confirmation message.
I wrote the following function in javascript
function OnSave()
{
var ddlStatus=document.getElementById("ddlStatus");
if(ddlStatus.selectedIndex==1)
{
if(confirm('Are you sure want to close this ticket number?')==false)
{
return false;
}
}
}

On clicking the Button, i'm getting a confirmation message with OK and
Cancel.After clicking Cancel,return false is not working and the server side
code is being called.

Thanks in advance
Srinivas
 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      02-07-2007
"srinivas" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

function OnSave()
{
var ddlStatus=document.getElementById("ddlStatus");
if(ddlStatus.selectedIndex==1)
{
return confirm('Are you sure want to close this ticket number?');
}
}


 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      02-07-2007
Two points:

1. To make it work set OnClientClick="return OnSave();"

2. To eliminate some unnecessary lines of code replace
if(confirm('Are you sure want to close this ticket number?')==false)
{
return false;
}
with just
return confirm('Are you sure want to close this ticket number?');

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


"srinivas" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> I'm having an ASP.net page with a dropdown list box named ddlStatus, a
> button and editable gridview.
> I wrote a small javascript function "OnSave()" and called it on the event
> 'onClientClick()' event of the button.
> I have a required field validator for the text boxes in the grid view

also.
> The dropdown list box contains 2 values 'Open' Or 'Close'.
> If the user clicks the Button by selecting the 'Close' then i have to
> display a confirmation message.
> I wrote the following function in javascript
> function OnSave()
> {
> var ddlStatus=document.getElementById("ddlStatus");
> if(ddlStatus.selectedIndex==1)
> {
> if(confirm('Are you sure want to close this ticket number?')==false)
> {
> return false;
> }
> }
> }
>
> On clicking the Button, i'm getting a confirmation message with OK and
> Cancel.After clicking Cancel,return false is not working and the server

side
> code is being called.
>
> Thanks in advance
> Srinivas



 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      02-07-2007
if you are running any validators, the button calls client script to
postback, so you need to do the following (works with and without a
validator):

<asp:button onclientclick="if (OnSave() == false) return false; />

-- bruce (sqlwork.com)

srinivas wrote:
> Hi,
> I'm having an ASP.net page with a dropdown list box named ddlStatus, a
> button and editable gridview.
> I wrote a small javascript function "OnSave()" and called it on the event
> 'onClientClick()' event of the button.
> I have a required field validator for the text boxes in the grid view also.
> The dropdown list box contains 2 values 'Open' Or 'Close'.
> If the user clicks the Button by selecting the 'Close' then i have to
> display a confirmation message.
> I wrote the following function in javascript
> function OnSave()
> {
> var ddlStatus=document.getElementById("ddlStatus");
> if(ddlStatus.selectedIndex==1)
> {
> if(confirm('Are you sure want to close this ticket number?')==false)
> {
> return false;
> }
> }
> }
>
> On clicking the Button, i'm getting a confirmation message with OK and
> Cancel.After clicking Cancel,return false is not working and the server side
> code is being called.
>
> Thanks in advance
> Srinivas

 
Reply With Quote
 
=?Utf-8?B?c3Jpbml2YXM=?=
Guest
Posts: n/a
 
      02-08-2007
It's working
Thanks a lot...


"bruce barker" wrote:

> if you are running any validators, the button calls client script to
> postback, so you need to do the following (works with and without a
> validator):
>
> <asp:button onclientclick="if (OnSave() == false) return false; />
>
> -- bruce (sqlwork.com)
>
> srinivas wrote:
> > Hi,
> > I'm having an ASP.net page with a dropdown list box named ddlStatus, a
> > button and editable gridview.
> > I wrote a small javascript function "OnSave()" and called it on the event
> > 'onClientClick()' event of the button.
> > I have a required field validator for the text boxes in the grid view also.
> > The dropdown list box contains 2 values 'Open' Or 'Close'.
> > If the user clicks the Button by selecting the 'Close' then i have to
> > display a confirmation message.
> > I wrote the following function in javascript
> > function OnSave()
> > {
> > var ddlStatus=document.getElementById("ddlStatus");
> > if(ddlStatus.selectedIndex==1)
> > {
> > if(confirm('Are you sure want to close this ticket number?')==false)
> > {
> > return false;
> > }
> > }
> > }
> >
> > On clicking the Button, i'm getting a confirmation message with OK and
> > Cancel.After clicking Cancel,return false is not working and the server side
> > code is being called.
> >
> > Thanks in advance
> > Srinivas

>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
return false not working in IE iswariak@gmail.com Javascript 0 05-31-2007 09:55 AM
False positive, false intrusion, false alarm Nick Computer Security 3 04-26-2006 07:40 PM
"return false" gives a blank page with the word "false" ? kurtj@ev1.net Javascript 10 02-16-2006 04:13 PM
onselectstart="return false" ondragstart="return yingjian.ma1955@gmail.com Javascript 1 10-06-2005 10:18 PM
difference between return true; and return false; w i l l Javascript 4 07-04-2003 10:05 PM



Advertisments