473,320 Members | 2,073 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,320 software developers and data experts.

Any way for JavaScript to abort postback from an ASP.NET Button?

I have a small JavaScript event handler that runs when a Button is clicked.
This function is called before the postback. I would like to prevent the
execution of the postback in that function under a certain condition.

Possible?
Nov 19 '05 #1
3 4584
On Wed, 15 Jun 2005 00:37:13 -0500, None <no**@nowhere.com> wrote:
I have a small JavaScript event handler that runs when a Button is
clicked.
This function is called before the postback. I would like to prevent the
execution of the postback in that function under a certain condition.

Possible?


Can't remember, is doing return false; an option? Been awhile since I
played with this regarding attributes on buttons.

Otherwise you can essentially 'override' the __doPostBack function. See
the comments in this post for some useful info:

http://groups-beta.google.com/group/...ostback&rnum=3

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 19 '05 #2
Return false from the javascript function.

Here's some server side code that uses javascript to display a confirmation
message.

myDeleteButton.Attributes.Add("onclick", _
"return confirm('Are you sure you want to delete?');")

In this example, the Delete button will post back only if the person
confirms they want to delete. Otherwise your server code is never called in
response to the button click.

Here's a more detailed analysis of your options, including a free control
that can handle many of the options for you.
http://SteveOrr.net/articles/ClientSideSuite.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"None" <no**@nowhere.com> wrote in message
news:ez**************@TK2MSFTNGP15.phx.gbl...
I have a small JavaScript event handler that runs when a Button is clicked.
This function is called before the postback. I would like to prevent the
execution of the postback in that function under a certain condition.

Possible?

Nov 19 '05 #3
What is the difference between these two
>> imgUpdatePhy.Attributes.Add("onClick", "return fnUpdateAlert();"); This code is written in Aspx page
function fnUpdateAlert() { var strConfirm=confirm("Do you wish to Update!");
if(strConfirm != true) { return false; } }
myDeleteButton.Attributes.Add("onclick", "return confirm('Are you
>> sure you want to delete?');")

Raghuram

"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:uI**************@TK2MSFTNGP15.phx.gbl... Return false from the javascript function.

Here's some server side code that uses javascript to display a
confirmation
message.

myDeleteButton.Attributes.Add("onclick", _
"return confirm('Are you sure you want to delete?');")

In this example, the Delete button will post back only if the person
confirms they want to delete. Otherwise your server code is never called
in
response to the button click.

Here's a more detailed analysis of your options, including a free control
that can handle many of the options for you.
http://SteveOrr.net/articles/ClientSideSuite.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"None" <no**@nowhere.com> wrote in message
news:ez**************@TK2MSFTNGP15.phx.gbl...
I have a small JavaScript event handler that runs when a Button is
clicked.
This function is called before the postback. I would like to prevent the
execution of the postback in that function under a certain condition.

Possible?


Nov 19 '05 #4

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

Similar topics

14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
21
by: Martin Eyles | last post by:
I am trying to get javascript to cause a page to post back. I have tried calling _doPostBack from my script, but generates an error "object expected". I think this is because the page's script...
6
by: domtam | last post by:
First of all, my ASP.NET application has to support browser with Javascript disabled. In the application There is a control that looks like a text hyperlink, but the server-side has to do...
6
by: tshad | last post by:
I am trying to set up a Javascript popup box that has a way of sending back a message to asp.net on how to process some data. At the moment I am just doing: ...
4
by: =?Utf-8?B?T3Bh?= | last post by:
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...
4
by: Peter | last post by:
ASP.NET I have an application which use ASP.NET Autocomplete extender which works great. But I have a question how to update all the fields on the screen using Ajax. Users starts typing in a...
2
Frinavale
by: Frinavale | last post by:
JavaScript in ASP.NET Using JavaScript in ASP.NET pages can make your application seem to work faster and prevent unnecessary calls to the server. JavaScript can be used to perform client-side...
8
by: MAX2006 | last post by:
Hi, I am doing some client side javascipt work. I have a handler for window.onUnload event and within the code; I need to know the name of the asp.net button caused the postback. How can I do...
2
by: joelkeepup | last post by:
Hi, I made a change this morning and now im getting an error that says either "a is undefined or null" or "e is undefined or null" the microsoft ajax line is below, I have no idea how to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.