Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   CodeBehind with <Save> and JS return false; (http://www.velocityreviews.com/forums/t687259-codebehind-with-save-and-js-return-false.html)

Jennifer Mathews 06-09-2009 11:26 AM

CodeBehind with <Save> and JS return false;
 
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;
}


Joern Schou-Rode 06-09-2009 11:55 AM

Re: CodeBehind with <Save> and JS return false;
 
On Tue, 09 Jun 2009 13:26:15 +0200, Jennifer Mathews
<waltersjennifer@live.com> 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 06-09-2009 12:01 PM

Re: CodeBehind with <Save> and JS return false;
 
That did the trick. Thanks


"Mark Rae [MVP]" <mark@markNOSPAMrae.net> wrote in message
news:eLk3lbP6JHA.1420@TK2MSFTNGP04.phx.gbl...
> "Jennifer Mathews" <waltersjennifer@live.com> wrote in message
> news:FE1D8E61-708E-4906-B588-FCAAE53929D0@microsoft.com...
>
>> 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 06-09-2009 12:05 PM

Re: CodeBehind with <Save> and JS return false;
 
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" <jsr@malamute.dk> wrote in message news:op.uu8914v831zpn8@marvin...
> On Tue, 09 Jun 2009 13:26:15 +0200, Jennifer Mathews <waltersjennifer@live.com>
> 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 06-09-2009 01:50 PM

Re: CodeBehind with <Save> and JS return false;
 
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" <jsr@malamute.dk> wrote in message
> news:op.uu8914v831zpn8@marvin...
>> On Tue, 09 Jun 2009 13:26:15 +0200, Jennifer Mathews
>> <waltersjennifer@live.com> 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/

>



All times are GMT. The time now is 10:11 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.