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

  • Home
  • SEARCH
  • 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 7870883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:44:28+00:00 2026-06-03T01:44:28+00:00

This seems like a common question but search is not returning anything. I have

  • 0

This seems like a common question but search is not returning anything.

I have the following code that executes before the page unloads.The problem is if the unload is a postback i do not want to fire my warning to the user but i can’t figure out how to differentiate between a postback and a user navigating to another page for example.

// This is executed before the page actually unloads
        $(window).bind("beforeunload", function () {

            if (prompt) {

                //prompt
                return true;
            }
            else {

                //reset our prompt variable
                prompt = true;
            }
        })

Running script in the code behind i.e. if Page.IsPostBack then set prompt is not an option.

Any ideas?

EDIT:

Here is the solution I ended up with:

 function DoNotPrompt() {
              prompt = false;
        }

I then added this to all the controls where the user could do something that result in a post back.

OnClientClick="DoNotPrompt()

Then checked this flag and only returned a string in “beforeunload” if the user was really moving away from the page i.e. not a postback.

I also had to use this code:
var magicInput = document.getElementById(‘__EVENTTARGET’);

    if (magicInput && magicInput.value) {
        // the page is being posted back by an ASP control 
        prompt = false;
    }

The reason being i had a custom user control that was a list box and I could not add the above method. So used this to catch that event and set the flag to false.

Not the most elegent solution.

Thanks,
Michael

  • 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-06-03T01:44:30+00:00Added an answer on June 3, 2026 at 1:44 am

    This may not cover all of the postback situations, but you can tell if the page was posted back by an ASP control by interrogating the __EVENTTARGET hidden input.

    This input is set by ASP when the page is posted back by an ASP control.

    var magicInput = document.getElementById('__EVENTTARGET');
    
    if (magicInput && magicInput.value) {
       // the page is being posted back by an ASP control
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question seems like it might be somewhat common, but I didn't find anything
This seems like a pretty softball question, but I always have a hard time
This seems like an obvious question but there does not appear to be an
This seems like it'd be a common question, but I cannot find it. Perhaps
Seems like this would be a common question, though I could not find it
I feel like this is a stupid question because it seems like common sense
This seems like it would be a common issue to be but I don't
This seems like a simple question, but I can't find it with the Stack
This seems like a basic question, but I haven't found any clear answers. Essentially,
This seems like a basic question, but it's still bugging me. Why doesn't MyObject

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.