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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:02:31+00:00 2026-05-12T05:02:31+00:00

I am hooking the window.onbeforeunload event in an aspx page. I need that not

  • 0

I am hooking the window.onbeforeunload event in an aspx page. I need that not to fire if I page a GridView that’s in an UpdatePanel on the same page.

I have tried hooking the PageRequestManager’s initializeRequest event but this fires too late, i.e. after onbeforeunload. I have also tried checking PageRequestManager.get_isInAsyncPostBack() in my onbeforeunload handler but that returns false too, gah!

I have read this SO thread :

537702

But that doesn’t make sense to me other than GridView page links cause an unload whereas buttons in a GridView column do not? Anybody know how to solve this? I’m guessing only way is to attach client-side click handler to all the GridView’s page anchors to set some boolean flag, but I’m not sure how to accomplish that in a reliable manner.

  • 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-12T05:02:31+00:00Added an answer on May 12, 2026 at 5:02 am

    Ok JQuery to the rescue!

    <script type="text/javascript">
        var flag = true;
        window.onbeforeunload = beforeUnloading;
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_pageLoaded(initPagers);
    
        function initPagers() {
            $(".gridViewPagerStyle").click(function() { flag = false; });
        }
    
        function beforeUnloading(){
            if(flag)
                return "unloading";
    
            flag = true;
        }
    </script>
    
    :
    :   
    
    <asp:GridView ... PagerStyle-CssClass="gridViewPagerStyle" ... />
    
    :
    :
    

    Set a Css class for all pager links, use that to append javascript click handlers that set a flag when clicked, use flag to avoid onbeforeunload

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

Sidebar

Related Questions

I need to perform some action when my application receives focus. I've tried hooking
I have a WPF app that is using the MVVM pattern. Hooking up buttons
I need to recognize and fire an event when a file is going to
I'm having problems hooking up the mousedown event for the window using jQuery in
I'm getting in trouble by hooking window messages. I need to detect window text
Overview. I have a Windows Service written in C# .NET 4.0 that is hooking
I have a RichTextBox in .NET WinForms. I have been hooking up hot keys
I have a problem hooking int 09h I've changed the pointer to my new
I have a windows exe app that used to sends packets to a server
I have this flash application that opens a socket connection with a server. What

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.