CodeBehind with <Save> and JS return false;

  • Thread starter Thread starter Jennifer Mathews
  • Start date Start date
J

Jennifer Mathews

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;
}
 
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 :)
 
That did the trick. Thanks


Mark Rae said:
Yes, it will do...



Because you're not capturing the JavaScript function's return value - you're simply
telling it to run...



OnClientClick="return ucEU_Add_User_cmdSave();" />
 
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
 
this is what the custom validator is for. pretty trivial to require
field(s) based on a checkbox.

-- bruce (sqlwork.com)

Jennifer said:
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
 
Back
Top