CodeBehind with <Save> and JS return false;

Discussion in 'ASP .Net' started by Jennifer Mathews, Jun 9, 2009.

  1. In the code below, I have a <Save> button firing. I have taken out the JavaScript
    validation code but it ends with "return false;" if there are errors. The Code Behind
    still fires eventhough there is a "return false;" statement in the JavaScript. Why? I
    thought that should prevent the Code Behind from firing. How should I stop it from
    firing when there is a validation problem?

    Thanks

    <asp:ImageButton ID="cmdSave" runat="server" ="~/Save.jpg" AlternateText="Save"
    ValidationGroup="rfvg_Submit" OnClientClick="ucEU_Add_User_cmdSave();" />

    function ucEU_Add_User_cmdSave() {
    alert("START ucEU_Add_User_cmdSave");
    // Make sure either Cmp_Item_ID or Cmp_Item_Name is filled-in.
    return false;
    }
     
    Jennifer Mathews, Jun 9, 2009
    #1
    1. Advertising

  2. On Tue, 09 Jun 2009 13:26:15 +0200, Jennifer Mathews
    <> wrote:

    > I have taken out the JavaScript validation code


    Are you aware that ASP.NET has a built-in framework for input validation,
    consisting of a number of web controls (RequiredFieldValidator,
    RangeValidator, ValidationSummary, etc.)?

    You might have good reasons to the manually implement your validation
    logic - if so please disregard this post :)

    --
    Joern Schou-Rode
    http://malamute.dk/
     
    Joern Schou-Rode, Jun 9, 2009
    #2
    1. Advertising

  3. That did the trick. Thanks


    "Mark Rae [MVP]" <> wrote in message
    news:...
    > "Jennifer Mathews" <> wrote in message
    > news:...
    >
    >> The Code Behind still fires eventhough there is a "return false;" statement in the
    >> JavaScript.

    >
    > Yes, it will do...
    >
    >
    >> Why?

    >
    > Because you're not capturing the JavaScript function's return value - you're simply
    > telling it to run...
    >
    >
    >> How should I stop it from firing when there is a validation problem?

    >
    > OnClientClick="return ucEU_Add_User_cmdSave();" />
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
     
    Jennifer Mathews, Jun 9, 2009
    #3
  4. I am aware of it.

    In the JavaScript I am validating conditional data input which I don't believe the
    built-in ASP.Net validation controls can do. (i.e. A required field validator is great
    except when it is only required if a checkbox is checked.)

    If I am incorrect [ which would only be the first time this year :) ] , please tell me.

    Thanks

    "Joern Schou-Rode" <> wrote in message news:eek:p.uu8914v831zpn8@marvin...
    > On Tue, 09 Jun 2009 13:26:15 +0200, Jennifer Mathews <>
    > wrote:
    >
    >> I have taken out the JavaScript validation code

    >
    > Are you aware that ASP.NET has a built-in framework for input validation, consisting
    > of a number of web controls (RequiredFieldValidator, RangeValidator,
    > ValidationSummary, etc.)?
    >
    > You might have good reasons to the manually implement your validation logic - if so
    > please disregard this post :)
    >
    > --
    > Joern Schou-Rode
    > http://malamute.dk/
     
    Jennifer Mathews, Jun 9, 2009
    #4
  5. Jennifer Mathews

    bruce barker Guest

    this is what the custom validator is for. pretty trivial to require
    field(s) based on a checkbox.

    -- bruce (sqlwork.com)

    Jennifer Mathews wrote:
    > I am aware of it.
    >
    > In the JavaScript I am validating conditional data input which I don't
    > believe the
    > built-in ASP.Net validation controls can do. (i.e. A required field
    > validator is great
    > except when it is only required if a checkbox is checked.)
    >
    > If I am incorrect [ which would only be the first time this year :) ] ,
    > please tell me.
    >
    > Thanks
    >
    > "Joern Schou-Rode" <> wrote in message
    > news:eek:p.uu8914v831zpn8@marvin...
    >> On Tue, 09 Jun 2009 13:26:15 +0200, Jennifer Mathews
    >> <> wrote:
    >>
    >>> I have taken out the JavaScript validation code

    >>
    >> Are you aware that ASP.NET has a built-in framework for input
    >> validation, consisting of a number of web controls
    >> (RequiredFieldValidator, RangeValidator, ValidationSummary, etc.)?
    >>
    >> You might have good reasons to the manually implement your validation
    >> logic - if so please disregard this post :)
    >>
    >> --
    >> Joern Schou-Rode
    >> http://malamute.dk/

    >
     
    bruce barker, Jun 9, 2009
    #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. trans.  (T. Onoma)
    Replies:
    0
    Views:
    156
    trans. (T. Onoma)
    Sep 25, 2004
  2. trans.  (T. Onoma)
    Replies:
    1
    Views:
    169
    David A. Black
    Sep 25, 2004
  3. w i l l
    Replies:
    4
    Views:
    244
    Dan Brussee
    Jul 4, 2003
  4. Replies:
    1
    Views:
    441
    Randy Webb
    Oct 6, 2005
  5. Replies:
    10
    Views:
    314
    Thomas 'PointedEars' Lahn
    Feb 16, 2006
Loading...

Share This Page