473,414 Members | 1,707 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.

How to cancel http request from javascript

Hi,

I'm not sure if the title is correct. Here's what I am having trouble with:
I have a server side button control where I am calling a javascript function
via the OnClientClick property. I also have a server side event handler to
handle the On_Click event on the postback. I wish to cancel the postback
based on whether the javascript function returns true or false. The problem
is that the I never get a postback and ofcourse the On_Click event never
fires. Here is my js:

function ConfirmSubmission()
{
return confirm("Do you want to continue?");
}

I set the button OnClientClick property as follows:
OnClientClick="ConfirmSubmission(); And I do have runat server to true.

How can I get this to work? Thanks in advance.


May 12 '07 #1
4 8852
Opa wrote:
Hi,

I'm not sure if the title is correct. Here's what I am having
trouble with: I have a server side button control where I am calling
a javascript function via the OnClientClick property. I also have a
server side event handler to handle the On_Click event on the
postback. I wish to cancel the postback based on whether the
javascript function returns true or false. The problem is that the I
never get a postback and ofcourse the On_Click event never fires.
Here is my js:

function ConfirmSubmission()
{
return confirm("Do you want to continue?");
}

I set the button OnClientClick property as follows:
OnClientClick="ConfirmSubmission(); And I do have runat server to
true.

How can I get this to work? Thanks in advance.
It should be:
OnClientClick="return ConfirmSubmission();"

The word "return" is the key word.

--

Riki
May 12 '07 #2
Thanks for the reply. I tried this, but the postback is never issue (i.e.
the server side OnClick event is never fired)
What's interesting is if I set the OnClientClick property of the button to
"return false;" or "return true;", I never get a postback. If I leave this
blank. I do get a postback. Shouldn't the "return true" cause the button to
proceed to a postback
or having any return value will stop the postback? The bottom line is I
want to control whether the postback is fired based on the return value of a
javascript call.
How can this be done?

"Riki" wrote:
Opa wrote:
Hi,

I'm not sure if the title is correct. Here's what I am having
trouble with: I have a server side button control where I am calling
a javascript function via the OnClientClick property. I also have a
server side event handler to handle the On_Click event on the
postback. I wish to cancel the postback based on whether the
javascript function returns true or false. The problem is that the I
never get a postback and ofcourse the On_Click event never fires.
Here is my js:

function ConfirmSubmission()
{
return confirm("Do you want to continue?");
}

I set the button OnClientClick property as follows:
OnClientClick="ConfirmSubmission(); And I do have runat server to
true.

How can I get this to work? Thanks in advance.

It should be:
OnClientClick="return ConfirmSubmission();"

The word "return" is the key word.

--

Riki
May 12 '07 #3
"Opa" <Op*@discussions.microsoft.comwrote in message
news:DF**********************************@microsof t.com...

Does this work for you?

<asp:Button ID="cmdDelete" runat="server" OnClick="cmdDelete_Click"
OnClientClick="return confirm('Do you want to continue?');" Text="Delete" />
--
http://www.markrae.net

May 12 '07 #4
Mark, I had the UseSubmitBehavior="False" when I changed it to true, the
logic works as expected. However, in a related question, I don't want any
action when the user hits the enter key, so I suppose I have to trap the
keypresses.

Thanks for the help.

"Mark Rae" wrote:
"Opa" <Op*@discussions.microsoft.comwrote in message
news:DF**********************************@microsof t.com...

Does this work for you?

<asp:Button ID="cmdDelete" runat="server" OnClick="cmdDelete_Click"
OnClientClick="return confirm('Do you want to continue?');" Text="Delete" />
--
http://www.markrae.net

May 12 '07 #5

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

Similar topics

17
by: Larry Woods | last post by:
I have a server page that has served an HTML page with a "Cancel" button on it, BUT this server page has not completed and is running a 15-30 second process before it completes. I want the browser...
1
by: Daniel | last post by:
in Application_BeginRequest how do i cancel the request and send back a message?
6
by: Ken Varn | last post by:
I have an ASP.NET form that may take a very long time to process a particular request. If the user closes the browser window, the request will continue to process until it completes. This is a...
1
by: Sergey Zuyev | last post by:
Hello all I have simple edit form. When user saves data that contains restricted characters such as (< , etc.) , regular expression validator will display a warning message. It all works fine,...
3
by: No_Spam | last post by:
How do I cancel submit process if certain fields are not filled in my ASP.NET form? I need to know how to do it using the Click sub for the submit button (in the .vb file) and not using javascript,...
4
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I change the confirm box to say yes/no or default to cancel?...
4
by: Chamnap | last post by:
I develop a form allow the user to upload with the hidden iframe. While in the progress, I allow the user to cancel their upload. In javascript, does it have cancel the request to the server. I...
7
by: John Gault | last post by:
I experimented with a snippet of JavaScript that will display a "Please Wait" message and graphic while the results of a cgi script is running (the script grabs a bunch of data and formats it in a...
13
Frinavale
by: Frinavale | last post by:
I've been trying all morning to cancel a form submit to the server. I have a JavaScript Object that determines whether or not the page should be submitted to the server depending on whether the...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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,...

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.