New to Telerik UI for ASP.NET MVCStart a free 30-day trial

Show Confirmation Popup When User Leaves the Page with Unsaved Grid Changes

Environment

ProductTelerik UI for ASP.NET MVC Grid
Progress Telerik UI for ASP.NET MVC version2024.4.1112

Description

How can I detect changes in an InLine editable Grid when the user tries to leave the page and prompt the user with a warning message about the unsaved changes?

Solution

To detect the changes in the Grid when the user attempts to navigate away from the page with the Grid, you can check whether there has been a change in the Grid's DataSource. If at least one change occurs, show the prompt.

  1. Handle the beforeunload event of the current window.
  2. Get a reference to the Grid and access its DataSource.
  3. Check the dirty flag of the data items, which indicates that the data item has been changed.
  4. Show the popup if at least one change occurs.
Razor
    @(Html.Kendo().Grid<ProductViewModel>()
        .Name("grid")
        .Editable(editable => editable.Mode(GridEditMode.InLine))
       ...//  Additional configuration.
    )

More ASP.NET MVC Grid Resources

See Also