473,414 Members | 1,630 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,414 software developers and data experts.

Return false is not working in JavaScript

Hi,
I'm having an ASP.net page with a dropdown list box named ddlStatus, a
button and editable gridview.
I wrote a small javascript function "OnSave()" and called it on the event
'onClientClick()' event of the button.
I have a required field validator for the text boxes in the grid view also.
The dropdown list box contains 2 values 'Open' Or 'Close'.
If the user clicks the Button by selecting the 'Close' then i have to
display a confirmation message.
I wrote the following function in javascript
function OnSave()
{
var ddlStatus=document.getElementById("ddlStatus");
if(ddlStatus.selectedIndex==1)
{
if(confirm('Are you sure want to close this ticket number?')==false)
{
return false;
}
}
}

On clicking the Button, i'm getting a confirmation message with OK and
Cancel.After clicking Cancel,return false is not working and the server side
code is being called.

Thanks in advance
Srinivas
Feb 7 '07 #1
4 13433
"srinivas" <sr******@discussions.microsoft.comwrote in message
news:F5**********************************@microsof t.com...

function OnSave()
{
var ddlStatus=document.getElementById("ddlStatus");
if(ddlStatus.selectedIndex==1)
{
return confirm('Are you sure want to close this ticket number?');
}
}
Feb 7 '07 #2
Two points:

1. To make it work set OnClientClick="return OnSave();"

2. To eliminate some unnecessary lines of code replace
if(confirm('Are you sure want to close this ticket number?')==false)
{
return false;
}
with just
return confirm('Are you sure want to close this ticket number?');

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"srinivas" <sr******@discussions.microsoft.comwrote in message
news:F5**********************************@microsof t.com...
Hi,
I'm having an ASP.net page with a dropdown list box named ddlStatus, a
button and editable gridview.
I wrote a small javascript function "OnSave()" and called it on the event
'onClientClick()' event of the button.
I have a required field validator for the text boxes in the grid view
also.
The dropdown list box contains 2 values 'Open' Or 'Close'.
If the user clicks the Button by selecting the 'Close' then i have to
display a confirmation message.
I wrote the following function in javascript
function OnSave()
{
var ddlStatus=document.getElementById("ddlStatus");
if(ddlStatus.selectedIndex==1)
{
if(confirm('Are you sure want to close this ticket number?')==false)
{
return false;
}
}
}

On clicking the Button, i'm getting a confirmation message with OK and
Cancel.After clicking Cancel,return false is not working and the server
side
code is being called.

Thanks in advance
Srinivas

Feb 7 '07 #3
if you are running any validators, the button calls client script to
postback, so you need to do the following (works with and without a
validator):

<asp:button onclientclick="if (OnSave() == false) return false; />

-- bruce (sqlwork.com)

srinivas wrote:
Hi,
I'm having an ASP.net page with a dropdown list box named ddlStatus, a
button and editable gridview.
I wrote a small javascript function "OnSave()" and called it on the event
'onClientClick()' event of the button.
I have a required field validator for the text boxes in the grid view also.
The dropdown list box contains 2 values 'Open' Or 'Close'.
If the user clicks the Button by selecting the 'Close' then i have to
display a confirmation message.
I wrote the following function in javascript
function OnSave()
{
var ddlStatus=document.getElementById("ddlStatus");
if(ddlStatus.selectedIndex==1)
{
if(confirm('Are you sure want to close this ticket number?')==false)
{
return false;
}
}
}

On clicking the Button, i'm getting a confirmation message with OK and
Cancel.After clicking Cancel,return false is not working and the server side
code is being called.

Thanks in advance
Srinivas
Feb 8 '07 #4
It's working
Thanks a lot...
"bruce barker" wrote:
if you are running any validators, the button calls client script to
postback, so you need to do the following (works with and without a
validator):

<asp:button onclientclick="if (OnSave() == false) return false; />

-- bruce (sqlwork.com)

srinivas wrote:
Hi,
I'm having an ASP.net page with a dropdown list box named ddlStatus, a
button and editable gridview.
I wrote a small javascript function "OnSave()" and called it on the event
'onClientClick()' event of the button.
I have a required field validator for the text boxes in the grid view also.
The dropdown list box contains 2 values 'Open' Or 'Close'.
If the user clicks the Button by selecting the 'Close' then i have to
display a confirmation message.
I wrote the following function in javascript
function OnSave()
{
var ddlStatus=document.getElementById("ddlStatus");
if(ddlStatus.selectedIndex==1)
{
if(confirm('Are you sure want to close this ticket number?')==false)
{
return false;
}
}
}

On clicking the Button, i'm getting a confirmation message with OK and
Cancel.After clicking Cancel,return false is not working and the server side
code is being called.

Thanks in advance
Srinivas
Feb 8 '07 #5

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

Similar topics

3
by: Varun | last post by:
Hi There, I have a form("myRequest.asp") and the values from it are retrieved into the page ("output_Print.asp") on which I have two buttons('Save As Complete' and 'Save As Incomplete'). When the...
1
by: Colin Hale | last post by:
I have a problem (amongst others)... I have the following code which sends 2 emails. I only want to send one! <A ONCLICK="OnActionClick('E-Mail')" ID="EMailNowAnchor" NAME="EMailNowAnchor"...
2
by: s_m_b | last post by:
Do you have to use the onClick attrib to have return false work? i.e. is it possible to do <a href="javascript:somefunct();return false;"> and have the page not reload with 'false' or the...
13
by: kurtj | last post by:
Hello Gurus: I have a validation script (below) that is somehow messed up. If the Name field is blank, I get the alert message, then the browser window goes to a blank document with the word...
4
by: ameyas | last post by:
hi all, i am using an image which has image map and i provide the href action url. i have provided the url to open a pop up window like "javascript:window.open('www.google.com');" but on...
8
by: Peter Afonin | last post by:
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...
2
by: FunkHouse9 | last post by:
I have 2 functions, the first one, "GetSelectedItem" is determining which radio button was selected and running the "formvalidation" function if needed. This is working fine. My problem is getting...
4
by: cssExp | last post by:
hello, i want to check for errors on submitting a form, on encountering an error it runs a function and returns a false preventing form submit. I have implemented that. function eCheck() { ...
5
by: dangt85 | last post by:
Hello, I have the following page: ... <style type="text/css"> body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.