Prevent Losing Batch Editing Changes on Paging or any other PostBack

7 posts, 0 answers
  1. Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 27 Feb 2014 Link to this post

    Requirements

    .NET version

     3.5+

    Visual Studio

     2010+

    programming language

     JavaScript

    browser support

     all browsers supported by Telerik UI


    PROJECT DESCRIPTION

    When using a RadGrid with enabled Batch editing functionality, it is possible to forget or neglect saving the recent changes before moving to another page, sorting, filtering or any other Postback action. This code-library demonstrates how to prevent the action if there are any unsaved Batch changes. It provides four approaches to choose from depending on your specific requirements:
    • SimpleStandardConfirm: The most basic implementation which prevents only paging.
    • SimpleRadConfirm: Prevents only paging, but this time with RadWindow.
    • AdvancedStandardConfirm: Demonstrates how to prevent paging, sorting, other PostBack actions from external elements, as well as, closing the browser or navigating to another page without saving the changes.
    • AdvancedRAdConfirm: The same as AdvancedStandardConfirm, but using RadWindow confirmation wherever possible.

    You can find additional information about the Advanced confirm pages in the comments of their respective script files.


     
  2. Ralf
    Ralf avatar
    8 posts
    Member since:
    May 2012

    Posted 17 Nov 2014 Link to this post

    The advanced samples are not working. If i edit the data then it refreshes it to the value before and nothing happens. What´s wrong?
  3. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 20 Nov 2014 Link to this post

    Hello Ralf,

    Actually the sample only shows how to prevent the user from performing an action that would lead to the loss of the current changes. However the example does not illustrates how to save the user changes. In order to achieve this you can follow one of the following approaches.
    1. Bind the grid to a data source control that supports automatic operations as demonstrated here.
    2. Subscribing to the OnBatchEditCommand event, extracting the user changes from the arguments and manually update the database/data source to which the grid is bound. An example on how to access the values from the event arguments is provided here.
    3. If client-side binding will be used you can bind the grid to a RadClientDataSource and enable its batch operations. Possible realization of this scenario can be observed here.


    Regards,
    Angel Petrov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  4. Jan
    Jan avatar
    18 posts
    Member since:
    Mar 2014

    Posted 24 Feb 2015 in reply to Telerik Admin Link to this post

    Hello Telerik Admins,

    thanks a lot for providing the Sample Code. Unfortunately, I'm running into a loop when using it. On using the change-page-buttons (not the numbers!), javascript shows the error "script28: Not enough stack memory".

    Any idea why this could happen and how to solve it?

    Any help would be very appreciated!

    Thanks in advance

    Jan
  5. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 24 Feb 2015 Link to this post

    Hi Jan,

    The recent release version of the controls introduced a new OnUserAction client-side event handler which makes this requirement a much more straightforward task. You can subscribe to this handler and cancel it depending on some specific conditions:
    http://demos.telerik.com/aspnet-ajax/grid/examples/data-binding/client-side/client-data-source-binding/defaultcs.aspx?product=clientdatasource

    This remove the necessity of including complex javascript logic to achieve this requirement.

    Hope this helps.


    Regards,
    Eyup
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Jan
    Jan avatar
    18 posts
    Member since:
    Mar 2014

    Posted 24 Feb 2015 in reply to Eyup Link to this post

    Hello Eyup,

    thanks a lot! I've achieved the desired behaviour using this (few) lines of code. I wanted the RadGrid to save automatically all changes if paging and wished by the user:
    function UserAction(sender, args) {
                if (sender.get_batchEditingManager().hasChanges(sender.get_masterTableView())) {
                    if (confirm("Änderungen müssen vor Seitenwechsel gespeichert werden! Fortfahren?")) {
                        sender.get_batchEditingManager().saveChanges(sender.get_masterTableView());
                        args.set_cancel(true);
                    }
                    else {
                        args.set_cancel(true);
                    }
                }
            }
  7. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 24 Feb 2015 Link to this post

    Hello Jan,

    I'm glad the suggested approach has proven helpful.
    Thank you for sharing your specific solution with our community.

    Regards,
    Eyup
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top