开发者

How can I identify that the GridViewRow is in edit mode before leaving or Navigating to other page? [duplicate]

开发者 https://www.devze.com 2023-04-08 19:30 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: How can I identify the edited row in GridView?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How can I identify the edited row in GridView?

My client wanted the GridView to display fields inside TextBoxes, and DropDownListBoxes only. He wanted the flexibility to update the Record just by clicking on the Update button after altering the values in the cell.

If user forgets to click on "Update" button for the current editing record before he navigates to some other page, then the program should prompt the user with the messag开发者_StackOverflowe "Do you want to save changes made to Emp.No 1003?" with "Yes", "No" options. If user selects "Yes" then the Emp record should be updated in the database. If users selects "No" then those changes should be discarded.

Can anybody please tell how can I achieve this requirement?


You can achieve this using some javascript and calling the window.onbeforeunload method.

Probably best have a global variable in your javascript code var changesMade = false;, Then when the user clicks on the Edit button, or makes changes, set the global variable to true.

Then in your window.onbeforeunload method use this code:

$(function(){
     window.onbeforeunload = function () {
        if (changesMade) {
            return "You have unsaved changes. Please Save all changes."; // customize this msg accordingly.
        }
    }
});

Please note I am using jQuery here to set up the method once the DOM has loaded.

0

精彩评论

暂无评论...
验证码 换一张
取 消