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

N

None

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?
 
C

Craig Deelsnyder

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...453e958/00ddf46325c7bc24?q=oldpostback&rnum=3
 
S

Steve C. Orr [MVP, MCSD]

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
 
R

Raghuram

What is the difference between these two
This code is written in Aspx page
function fnUpdateAlert() { var strConfirm=confirm("Do you wish to Update!");
if(strConfirm != true) { return false; } }

Raghuram
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top