Solved

Looking for Javascript to prevent AJAX postback

Posted on 2008-10-28
2
674 Views
Last Modified: 2010-08-05
I have an aspx page that has a few text fields and a custom control toolbar at the top. The toolbar has links like Save, Save and Close, Refresh and Back. When the page loads, I have a page variable called "ChangesMade" set to zero. When a user types into one of the text fields, I have a javascript function set the page variable "ChangesMade" equal to one. If the user clicks the "Back" button before saving, I check the "ChangesMade" variable and if necessary display a javascript confirm box to see if they want to save their changes. If they click that they do want to abort and have the option to save changes, I set Page_BlockSubmit = true; This works just fine and prevents thte page from posting back.

Now I have put all of this code into an AJAX update panel. When the user clicks Back, the function fires check the "ChangesMade" variable, sets the Page_BlockSubmit = true; BUT this does not prevent the postback. The page still goes to the server wich processes the "Back" command and the changes the user made are lost.

Does anyone know what javascript I need to prevent the AJAX postback from firing? Obviously Page_BlockSubmit = true; is not enough.
0
Comment
Question by:aiscom
  • 2
2 Comments
 

Author Comment

by:aiscom
ID: 22832247
I know there must be some way to this. The AJAX toolkit provides a ConfirmButtonExtender control which confirms a button press and prevents the page from posting back if the person clicks cancel.

I lloked at the Javascript for this control in my debugger, but this is pretty advanced Javascript. Can anyone see how this control is preventing the AJAX postback?
0
 

Accepted Solution

by:
aiscom earned 0 total points
ID: 22833952
I was able to stop the postback by using information from the following site:

http://www.dotnetcurry.com/ShowArticle.aspx?ID=176&AspxAutoDetectCookieSupport=1

I used the event handler to check if changes had been made and if so cancel.

Yeah, I get 500 points for answering my own question.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASCX file or a newer alternative? 1 41
tutorial for ebay api 3 55
exporting html table data 4 28
Testing of the web services 1 34
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question