CodeBehind with <Save> and JS return false;

  • Thread starter Jennifer Mathews
  • 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;
}
 
J

Joern Schou-Rode

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 :)
 
J

Jennifer Mathews

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();" />
 
J

Jennifer Mathews

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
 
B

bruce barker

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top