Return false is not working in JavaScript

Discussion in 'ASP .Net' started by =?Utf-8?B?c3Jpbml2YXM=?=, Feb 7, 2007.

  1. 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
    =?Utf-8?B?c3Jpbml2YXM=?=, Feb 7, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?c3Jpbml2YXM=?=

    Mark Rae Guest

    "srinivas" <> wrote in message
    news:...

    function OnSave()
    {
    var ddlStatus=document.getElementById("ddlStatus");
    if(ddlStatus.selectedIndex==1)
    {
    return confirm('Are you sure want to close this ticket number?');
    }
    }
    Mark Rae, Feb 7, 2007
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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
    Eliyahu Goldin, Feb 7, 2007
    #3
  4. =?Utf-8?B?c3Jpbml2YXM=?=

    bruce barker Guest

    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
    bruce barker, Feb 7, 2007
    #4
  5. 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

    >
    =?Utf-8?B?c3Jpbml2YXM=?=, Feb 8, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. André
    Replies:
    3
    Views:
    1,558
  2. w i l l
    Replies:
    4
    Views:
    230
    Dan Brussee
    Jul 4, 2003
  3. Replies:
    1
    Views:
    424
    Randy Webb
    Oct 6, 2005
  4. Replies:
    10
    Views:
    299
    Thomas 'PointedEars' Lahn
    Feb 16, 2006
  5. Replies:
    0
    Views:
    114
Loading...

Share This Page