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 9150693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:38:43+00:00 2026-06-17T11:38:43+00:00

I am working on a asp.net (framework 4) that has a requirement for the

  • 0

I am working on a asp.net (framework 4) that has a requirement for the user to be notified if they are trying to leave the page without saving changes. Well I found a solution by calling the onbeforeunload function via JavaScript. Works great in IE but not in Firefox, Safari or Chrome.

Now here is where the problem comes in. I’m using AJAX postbacks and if the user is prompted to save the changes before leaving the page, any controls inside of the update panel no longer will postback to the server. For example, if a press the save button that is inside of the update panel, nothing happens.

Here are some code snippets

javascript:

window.onbeforeunload = function (e) {
    if (doBeforeUnload() == true) {
        var ev = e || window.event;
        // For IE and Firefox prior to version 4
        if (ev) {
            ev.returnValue = "You have modified the data entry fields since the last time it was saved. If you leave this page, " +
                "any changes will be lost. To save these changes, click Cancel to return to the page, and then Save the data.";
        }
        // For Safari
        return "You have modified the data entry fields since the last time it was saved. If you leave this page, " +
                "any changes will be lost. To save these changes, click Cancel to return to the page, and then Save the data.";

    }
}

ASP.NET:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
    <ContentTemplate>
        <%--no controls inside of this panel will postback to server if user clicks the “Stay on Page” button--%>
    </ContentTemplate>
</asp:UpdatePanel>

Seems to be plenty of posts on the net but no solutions. Any ides besides not using async postbacks?

  • 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-17T11:38:44+00:00Added an answer on June 17, 2026 at 11:38 am

    I came across this question when I was searching for the similar issue. I was able to solve this by doing the following:

    var doOnBeforeUnloadCheck = true;  // global to set in link button
    window.onbeforeunload = function (e) {
        if (doOnBeforeUnloadCheck && doBeforeUnload()) {
            // do stuff
        }
        // Make sure to always re-enable check to ensure the event will still trigger
        // where not specified to disable event.
        doOnBeforeUnloadCheck = true;  
    }
    

    In a LinkButton you just make sure to set the global to false before running any other javascript or doing the postback:

    <asp:LinkButton ID="yourButton" runat="server"
        OnClientClick="doOnBeforeUnloadCheck = false;" OnClick="yourButton_Click" />
    

    I came across this solution with help from the following link:

    http://www.jimandkatrin.com/CodeBlog/post/LinkButton-UpdatePanel-onbeforeunload.aspx

    I found this question before I found my answer so if anyone else has the same issue this might save them some time. Hope that helps.

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

Sidebar

Related Questions

I am working with master page in ASP.NET (3.5) MVC Framework (1.0). I am
I'm working in asp.net mvc 4 with Entity Framework 5 (with edmx). I'm trying
I am working in ASP.net with .Net Framework 2.0 and VS 2008 Team System
i've started working with ASP.NET MVC and using Entity Framework, concretely with SQLite db,
I am working through Steve Sanderson's book Pro ASP.NET MVC Framework and I having
I'm working on an import from a CSV file to my ASP.NET MVC3/C#/Entity Framework
After working with ASP.Net MVC, it has me thinking about Rails. I worked with
I am working on an Filter Attribute for ASP.Net MVC that will return a
While working with ASP.NET MVC, I have noticed that exception messages issued by the
I am working in asp.net .net framework 4, i have a data grid and

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.