473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

return false alternative

Hello,

I'm using Javascript in ASP.NET application to check whether at least one
checkbox in datagrid has been checked. If validation fails, the user gets a
warning. If he clicks OK, the form is submitted, if Cancel - nothing should
happen.

The ASP.NET code looks like this:

btnSubmit.Attributes.Add("onClick", "if (!(" & sClientSideValidate.ToString
& "))" _
& "{ confirm('You have not selected any DRs. Are you sure you want to submit
change?');return false}")

All validation is in sClientSideValidate.

The problem is with "return false". ASP.NET doesn't like the word "return".
If I use it - all my ASP.NET validation controls don't work. For instance,
if I use "return confirm" - I have a problem, if I use just "confirm" - I
have no problem.

Same with "return false". But in this case I don't know what could I use
instead of "return false". I have to use something to cancel form submission
if the user clicks "Cancel".

I'm not an expert in Javascript, so I hope someone could tell me - what
could I use instead of "return false" to get the same results?

I would appreciate your help.

Thank you,
--
Peter Afonin

Mar 20 '07 #1
8 4340
On Mar 19, 9:05 pm, "Peter Afonin" <pafo...@hotmail.comwrote:
Hello,

I'm using Javascript in ASP.NET application to check whether at least one
checkbox in datagrid has been checked. If validation fails, the user gets a
warning. If he clicks OK, the form is submitted, if Cancel - nothing should
happen.

The ASP.NET code looks like this:

btnSubmit.Attributes.Add("onClick", "if (!(" & sClientSideValidate.ToString
& "))" _
& "{ confirm('You have not selected any DRs. Are you sure you want to submit
change?');return false}")

All validation is in sClientSideValidate.

The problem is with "return false". ASP.NET doesn't like the word "return".
If I use it - all my ASP.NET validation controls don't work. For instance,
if I use "return confirm" - I have a problem, if I use just "confirm" - I
have no problem.

Same with "return false". But in this case I don't know what could I use
instead of "return false". I have to use something to cancel form submission
if the user clicks "Cancel".

I'm not an expert in Javascript, so I hope someone could tell me - what
could I use instead of "return false" to get the same results?

I would appreciate your help.

Thank you,

--
Peter Afonin
First of all your closing brace is not in the proper place, it should
be before the return statement. But you can do even better than that.
The confirm box returns the users selection so you can check for true
or false and return it:

I have no experience with ASP (I'm a JSP developer) but it should look
something like this:

btnSubmit.Attributes.Add("onclick", "function() = { if (! " &
sClientSideValidate.ToString & ") { return confirm('You have not
selected any DRs. Are you sure you want to submit change?'); } }");

HTH.
Mar 20 '07 #2
Thank you very much.

The function you wrote looks perfectly correct to me. However, I'm
getting error "Expected: '{'", and I cannot figure out where it could
be expected.

This is how this function looks in the source:

<input type="submit" name="btnSubmit" value="Submit"
onclick="function() = { if (! dgReport__ctl2_chkConf.checked ||
dgReport__ctl3_chkConf.checked ||dgReport__ctl4_chkConf.checked ||
dgReport__ctl5_chkConf.checked ||dgReport__ctl6_chkConf.checked)
{ return confirm('You have not selected any DRs. Are you sure you want
to submit change?'); } }if (typeof(Page_ClientValidate) == 'function')
Page_ClientValidate(); " language="javascript" id="btnSubmit"
class="button" />

Thank you,

Peter

On Mar 20, 6:49 am, "Tom Cole" <tco...@gmail.comwrote:
On Mar 19, 9:05 pm, "PeterAfonin" <pafo...@hotmail.comwrote:


Hello,
I'm using Javascript in ASP.NET application to check whether at least one
checkbox in datagrid has been checked. If validation fails, the user gets a
warning. If he clicks OK, the form is submitted, if Cancel - nothing should
happen.
The ASP.NET code looks like this:
btnSubmit.Attributes.Add("onClick", "if (!(" & sClientSideValidate.ToString
& "))" _
& "{ confirm('You have not selected any DRs. Are you sure you want to submit
change?');return false}")
All validation is in sClientSideValidate.
The problem is with "return false". ASP.NET doesn't like the word "return".
If I use it - all my ASP.NET validation controls don't work. For instance,
if I use "return confirm" - I have a problem, if I use just "confirm" - I
have no problem.
Same with "return false". But in this case I don't know what could I use
instead of "return false". I have to use something to cancel form submission
if the user clicks "Cancel".
I'm not an expert in Javascript, so I hope someone could tell me - what
could I use instead of "return false" to get the same results?
I would appreciate your help.
Thank you,
--
PeterAfonin

First of all your closing brace is not in the proper place, it should
be before the return statement. But you can do even better than that.
The confirm box returns the users selection so you can check for true
or false and return it:

I have no experience with ASP (I'm a JSP developer) but it should look
something like this:

btnSubmit.Attributes.Add("onclick", "function() = { if (! " &
sClientSideValidate.ToString & ") { return confirm('You have not
selected any DRs. Are you sure you want to submit change?'); } }");

HTH.- Hide quoted text -

- Show quoted text -

Mar 20 '07 #3
And one more thing I'd like to mention. I'm afraid this code will also
never work for me due to the same statement "return". This statement
breaks all further code execution, that's why my other validation
controls don't work. Is there a way to avoid it?

Thanks again,

Peter

On Mar 20, 6:49 am, "Tom Cole" <tco...@gmail.comwrote:
On Mar 19, 9:05 pm, "PeterAfonin" <pafo...@hotmail.comwrote:


Hello,
I'm using Javascript in ASP.NET application to check whether at least one
checkbox in datagrid has been checked. If validation fails, the user gets a
warning. If he clicks OK, the form is submitted, if Cancel - nothing should
happen.
The ASP.NET code looks like this:
btnSubmit.Attributes.Add("onClick", "if (!(" & sClientSideValidate.ToString
& "))" _
& "{ confirm('You have not selected any DRs. Are you sure you want to submit
change?');return false}")
All validation is in sClientSideValidate.
The problem is with "return false". ASP.NET doesn't like the word "return".
If I use it - all my ASP.NET validation controls don't work. For instance,
if I use "return confirm" - I have a problem, if I use just "confirm" - I
have no problem.
Same with "return false". But in this case I don't know what could I use
instead of "return false". I have to use something to cancel form submission
if the user clicks "Cancel".
I'm not an expert in Javascript, so I hope someone could tell me - what
could I use instead of "return false" to get the same results?
I would appreciate your help.
Thank you,
--
PeterAfonin

First of all your closing brace is not in the proper place, it should
be before the return statement. But you can do even better than that.
The confirm box returns the users selection so you can check for true
or false and return it:

I have no experience with ASP (I'm a JSP developer) but it should look
something like this:

btnSubmit.Attributes.Add("onclick", "function() = { if (! " &
sClientSideValidate.ToString & ") { return confirm('You have not
selected any DRs. Are you sure you want to submit change?'); } }");

HTH.- Hide quoted text -

- Show quoted text -

Mar 20 '07 #4
Peter wrote:
And one more thing I'd like to mention. I'm afraid this code
will also never work for me due to the same statement "return".
This statement breaks all further code execution, that's why my
other validation controls don't work. Is there a way to avoid
it?
<snip>

It is hard to believe that ASP.NET could really be as bad as you
have just described. However, as you are constructing your
javascript code from string values in another leagues couldn't
you disguise the "return" keyword? In javascript we could do:-

"ret"+"urn false;"

- or:-

"\u0072eturn false;" //replacing the r with its unicode escape sequnce.

- for example, thought there would be no need in javascript.

Richard.
Mar 20 '07 #5
There is nothing bad about ASP.NET. "return" stops any further
Javascript code execution, added to the button "onclick" event. That's
why any further client side validation is not possible. It's all
understandable. So playing with the characters won't help here.

Thanks,

Peter

On Mar 20, 3:36 pm, "Richard Cornford" <Rich...@litotes.demon.co.uk>
wrote:
Peterwrote:
And one more thing I'd like to mention. I'm afraid this code
will also never work for me due to the same statement "return".
This statement breaks all further code execution, that's why my
other validation controls don't work. Is there a way to avoid
it?

<snip>

It is hard to believe that ASP.NET could really be as bad as you
have just described. However, as you are constructing your
javascript code from string values in another leagues couldn't
you disguise the "return" keyword? In javascript we could do:-

"ret"+"urn false;"

- or:-

"\u0072eturn false;" //replacing the r with its unicode escape sequnce.

- for example, thought there would be no need in javascript.

Richard.

Mar 20 '07 #6
"Peter" <gu********@gmail.comwrote:
There is nothing bad about ASP.NET.
<snip>

Then why did you write "ASP.NET doesn't like the word "return"."? And why are you showing us server code
if your problem is only with the client-side code?

Richard.

Mar 20 '07 #7
I guess the word "doesn't like" wasn't the right one.

In this particular case the javascript can be added only using the
server-side code, because I have to itirate through the hundreds of rows of
the datagrid. Well, maybe it's possible to use pure javascript without
server-side code, but I don't know how. That's why I was showing how I added
this code - using the server-side scripts. But the output in the HTML source
is this (example):

<input type="submit" name="btnSubmit" value="Submit"
onclick="function() = { if (! dgReport__ctl2_chkConf.checked ||
dgReport__ctl3_chkConf.checked ||dgReport__ctl4_chkConf.checked ||
dgReport__ctl5_chkConf.checked ||dgReport__ctl6_chkConf.checked)
{ return confirm('You have not selected any DRs. Are you sure you want
to submit change?'); } }if (typeof(Page_ClientValidate) == 'function')
Page_ClientValidate(); " language="javascript" id="btnSubmit"
class="button" />

Peter

"Richard Cornford" <Ri*****@litotes.demon.co.ukwrote in message
news:et*******************@news.demon.co.uk...
"Peter" <gu********@gmail.comwrote:
>There is nothing bad about ASP.NET.
<snip>

Then why did you write "ASP.NET doesn't like the word "return"."? And why
are you showing us server code if your problem is only with the
client-side code?

Richard.
Mar 21 '07 #8
"Peter Afonin" wrote:
>I guess the word "doesn't like" wasn't the right one.
Attributing the attitude to ASP.NET doesn't appear to be right either.
In this particular case the javascript can be added only using
the server-side code, because I have to itirate through the
hundreds of rows of the datagrid. Well, maybe it's possible
to use pure javascript without server-side code, but I don't
know how.
That would be irrelevant.
That's why I was showing how I added this code - using the server-side scripts.
Yes, not knowing what you are doing will have you looking form the wrong thing in the wrong place much
of time.
But the output in the HTML source is this (example):

<input type="submit" name="btnSubmit" value="Submit"
onclick="function() = { if (! dgReport__ctl2_chkConf.checked ||
^^^^^^^^^^^^^^
There are at least two syntax errors there, so this will never even get to the point of executing a
return statement.
dgReport__ctl3_chkConf.checked ||dgReport__ctl4_chkConf.checked ||
^^^^^^^^^^^^^^^^^^^^^^^
You are not attempting anything cross-browser then?
dgReport__ctl5_chkConf.checked ||dgReport__ctl6_chkConf.checked)
{ return confirm('You have not selected any DRs. Are you sure you want
to submit change?'); } }if (typeof(Page_ClientValidate) == 'function')
Page_ClientValidate(); " language="javascript" id="btnSubmit"
^^^^^^^^^^^^^^^^^^^^
What on earth is that bizarre attribute doing there?
class="button" />
<snip>

The logic you seem to want to implement is more like:-

if(
(
!(
(dgReport__ctl2_chkConf.checked)||
(dgReport__ctl3_chkConf.checked)||
(dgReport__ctl4_chkConf.checked)||
(dgReport__ctl5_chkConf.checked)||
(dgReport__ctl6_chkConf.checked)
)
)&&(
!(
confirm(
'You have not selected any DRs. '+
'Are you sure you want to submit change?'
)
)
)
){
return false;
}else{
return (
(typeof Page_ClientValidate == 'function')?
Page_ClientValidate():
false
);
}

- or as a single return statement:-
return (
(
(
(
(dgReport__ctl2_chkConf.checked)||
(dgReport__ctl3_chkConf.checked)||
(dgReport__ctl4_chkConf.checked)||
(dgReport__ctl5_chkConf.checked)||
(dgReport__ctl6_chkConf.checked)
)||(
confirm(
'You have not selected any DRs. '+
'Are you sure you want to submit change?'
)
)
)&&(
(typeof Page_ClientValidate == 'function')&&
Page_ClientValidate()
)
)||(
false
)
);

Richard.
But return statements are not your problem at all.

Richard.

Mar 21 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

47
by: Martin DeMello | last post by:
It seems to be a fairly common pattern for an object-modifying method to return None - however, this is often quite inconvenient. For instance def f(lst1, lst2): g((lst1 + lst2).reverse()) #...
10
by: Mark Jerde | last post by:
I'm trying to learn the very basics of using an unmanaged C++ DLL from C#. This morning I thought I was getting somewhere, successfully getting back the correct answers to a C++ " int SumArray(int...
3
by: Sanjay Pais | last post by:
I know that string/char enum is not possible in c# (.NET2.0) I need to create the equivalent of this: public enum HOW_GOOD { AWESOME = "A", GREAT= "G", NOT_TOO_BAD = "N", TERRIBLE="T" }
15
by: AussieRules | last post by:
Hi, I have a need to do two selects against to stored proc's in my SQL db. At the moment, each SP is called and two different dataset are populate. Thats two round trips to the SQL server. ...
11
by: randomtalk | last post by:
hi, i have the following recursive function (simplified to demonstrate the problem): >>> def reTest(bool): .... result = .... if not bool: .... reTest(True) .... else: .... print...
16
by: DaTurk | last post by:
Hi, I have a c# application that needs to access c++ libraries, so it does this by using a managed layer of c++ CLI. Anyway, in the CLI function call, that calls the unmanaged function it...
8
by: vunet.us | last post by:
Why does IE6 ignores JavaScript's return false on a link and how to fix it? Firefox works perfect! <a href="page1.html" onclick="return test(this)">Test</a> JS: function test(obj) {...
13
by: cppquester | last post by:
A colleague told me that there is a rule about good stype that a function in C++ should have only one point of return (ie. return statement). Otherwise there might be trouble. I never heard about...
80
by: xicloid | last post by:
I'm making a function that checks the input integer and returns the value if it is a prime number. If the integer is not a prime number, then the function should return nothing. Problem is, I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.