RadGrid causes beforeunload to fire

2 posts, 0 answers
  1. Christopher Greaney
    Christopher Greaney avatar
    3 posts
    Member since:
    Oct 2018

    Posted 04 Jun 2020 Link to this post

        I am using a javascript to check for unsaved changes, but when editing, adding a new line or refreshing the grid, the unsaved changes message box appears.  how can i stop this?   javascript code below:


    <script type="text/javascript">
        // Store form state at page load
        var initial_form_state = $('#form1').serialize();

        // Store form state after form submit
        $('#form1').submit(function () {
            initial_form_state = $('#form1').serialize();

        // Check form changes before leaving the page and warn user if needed
        $(window).bind('beforeunload', function (e) {
            var form_state = $('#form1').serialize();
            if (initial_form_state != form_state) {
                var message = "You have unsaved changes on this page. Do you want to leave this page and discard your changes or stay on this page?";
                e.returnValue = message; // Cross-browser compatibility (src: MDN)
                return message;

  2. Doncho
    Doncho avatar
    96 posts

    Posted 09 Jun 2020 Link to this post


    The beforeunload event is fired when the document and its resources are about to be unloaded.

    By default refreshing the RadGrid causes a complete PostBack of the page and therefore the page is unloaded and loaded again, respectively the beforeunload event is fired.

    To avoid reloading the whole page, and firing the beforeunload event,  when a PostBack is forced by the RadGrid, you can enable AJAX for the RadGrid using one of the following approaches:

    Check out the Understanding AJAX Controls article to get a better overview of Ajaxifying Controls.

    I hope this will prove helpful!

    Kind regards,
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top