locked
Back button and ajax modalpopupextender RRS feed

  • Question

  • User-445160987 posted

    I have a site that allows users to search for drawing records. These records are displayed in a asp.net gridview. The user can select a record and it will send them to a details page. On this details page they can add information, delete information, etc... Now when they add or delete information I have a ajax modalpopupextender show so they can add or delete the information. Once they add or delete the information the modal popup closes and they are back on the details page. At this point if they click on the browsers back button it will bring them back to the ajax modal popup. Is there away to stop this behavior? I want them to go back to the page with the list of results. 

    Thanks,

    Friday, July 12, 2019 4:02 PM

Answers

  • User-719153870 posted

    Hi jsgray1023,

    According to your description, I created a demo to reproduce your problem.

    When I bind modalpopup to LinkButton and button, everything went well the problem didn’t happen.

    But it happened when I tried to bind it to a hiddenfield. Is this your case?

    I recommend that you can add an event to the browser's Back button of your ‘details page’ to jump to the specified page( details page) when it is clicked.

    Please refer to below codes in JS of your detailpage.aspx:

    ASPX:

    <script src="Scripts/jquery-3.3.1.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var isChanging = 0;
                location.hash = '1';
                window.onhashchange = function () {
                    // alert('1');
                    if (isChanging--) {
                        return false;
                    }
                    if (window.location.hash == "#backButtonClick") {
                        window.location = "./Detailpage.aspx"
                        isChanging = 1;
                    }
                    else {
                        isChanging = 2;
                        window.location.hash = "#backButtonClick";
                    }
                    window.location.hash = "#forward"
                }
            });
        </script>

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 15, 2019 5:51 AM

All replies

  • User-719153870 posted

    Hi jsgray1023,

    According to your description, I created a demo to reproduce your problem.

    When I bind modalpopup to LinkButton and button, everything went well the problem didn’t happen.

    But it happened when I tried to bind it to a hiddenfield. Is this your case?

    I recommend that you can add an event to the browser's Back button of your ‘details page’ to jump to the specified page( details page) when it is clicked.

    Please refer to below codes in JS of your detailpage.aspx:

    ASPX:

    <script src="Scripts/jquery-3.3.1.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var isChanging = 0;
                location.hash = '1';
                window.onhashchange = function () {
                    // alert('1');
                    if (isChanging--) {
                        return false;
                    }
                    if (window.location.hash == "#backButtonClick") {
                        window.location = "./Detailpage.aspx"
                        isChanging = 1;
                    }
                    else {
                        isChanging = 2;
                        window.location.hash = "#backButtonClick";
                    }
                    window.location.hash = "#forward"
                }
            });
        </script>

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 15, 2019 5:51 AM
  • User-445160987 posted

    Awesome, just what I was looking for. Thanks,

    Monday, July 15, 2019 12:48 PM