Thursday, 25 September 2014

Prevent a User Navigating Away from a Page with Unsaved Changes.

prevant user with unsaved chages

Description:-



In this example we explain that Prevent User Navigating Away from Page with Unsaved Changes

As we all know that many website or social media site provide facility like When you edits some data, and then closes current page or navigate to the current page without saving that data, most applications will warn the user that they have unsaved changes and display alert message like you want leave the current page or stay on the page .

In my application we have requirement if users will edit some data or some changes and navigate away from a page without saving their changes. Then we provide appropriate alert message to the user is that unsaved changes you want leave the current page or stay on the page, same functionality that Gmail provide when you navigate away with an unsaved message.



Restrict the size of File when Uploaded How to Restrict the size of File when uploaded by user

Dynamically Read/Write File in asp.Net How to Read Write File in Asp.Net using C#


Code:-


<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
    <script type="text/javascript">
        $.fn.extend({
            trackChanges: function () {
                $(":input", this).keyup(function () {
                    $(this.form).data("changed", true);
                });

                var form = $(this);
                $(form).submit(function () {
                    form.data("submitted", true);
                });
            },
            isChanged: function () {
                return this.data("changed") && !this.data("submitted");
            }
        });

        $(document).ready(function () {
            if ($('.detect_changes').length > 0) {
                $('.detect_changes').trackChanges();
                $(window).on('beforeunload', function () {
                    if ($('.detect_changes').isChanged()) {
                        return 'Your changes have not been saved.';
                    }
                });
            }
        });    </script>


 

0 comments:

Post a Comment