Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6621853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:19:31+00:00 2026-05-25T21:19:31+00:00

I have the following solution for stopping the users from accidentally leaving my registration

  • 0

I have the following solution for stopping the users from accidentally leaving my registration page:

var warning = true;

function CheckExit() {
    if (warning) {
        return "Changes done. Remember to save, blah blah.";
    }
}
window.onbeforeunload = CheckExit;

addToPostBack = function (func) {
    var old__doPostBack = __doPostBack;
    if (typeof __doPostBack != 'function') {
        __doPostBack = func;
    } else {
        __doPostBack = function (t, a) {
            if (func(t, a)) old__doPostBack(t, a);
        }
    }
};

$(document).ready(function () {

    $('#aspnetForm').submit(function () {
        warning = false;
        return true;
    });

    addToPostBack(function (t, a) {
        warning = false;
        return true;
    }); 

});

Most of this code is from different questions here on StackOverflow, and works just fine on my local debugging page; all ASP.Net controls (linkbuttons, buttons) can be clicked without a warning, but as soon as the user tries to close the window or navigate away, the warning is displayed.

However, when deployed to my server, the warning pops up when I click ASP.Net controls too (and I really do not want to warn the user that his changes isn’t saved when he clicks the “Save” button). Now, there is a difference between my local debugging page and the server: the server uses a different MasterPage with some ads in it, but after debugging with Firebug (see next paragraph), I can’t see how that should make a difference.

I have tried running different parts of the Javascript code by using Firebug to confirm that everything is loaded correctly (my first guess was that the section containing $(‘#aspnetForm’) wasn’t being loaded, since this seems to be the difference), but there is no improvement at all. The warning still pops up on every click of a link or a button.

My main problem is, I think, that I do not fully understand what the addToPostBack function does, and as such, I cannot properly debug it.

Is there anybody here who has any idea what might be wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:19:32+00:00Added an answer on May 25, 2026 at 9:19 pm

    It’s a guess, but you don’t have the conventional anti-conflict device which goes
    (function ($) { code here })(jQuery);
    so something might be conflicting with jQuery’s definition of ‘$’ which would stop the execution of the exception your code makes when someone is posting back.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Solution: SomeProject.Ria (non Silverlight code) SomeProject.Ria.Silverlight (Silverlight light code, namespace
I currently have the following in one solution: Core Project (data access, biz logic,
When using ASP.net webforms my usual solution would have following type of setup -
I have the following code in a full .NET framework solution: public delegate int
I have the following question, and it screams at me for a solution with
I have trouble finding a solution for the following problem: I have a lot
gem install heroku failed with following message and I have tried the solution here
Can someone recommend a hosted solution that answers the following requirements (I have seen
I'm forced to find a solution for the following situation: I have a h1
I've looked around but have yet to find a great solution the the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.