By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,518 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.