Solved

Looking for Javascript to prevent AJAX postback

Posted on 2008-10-28
2
667 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now