How to force new item to be saved before clicking add new again

4 posts, 0 answers
  1. Auvo
    Auvo avatar
    34 posts
    Member since:
    Jul 2011

    Posted 07 Nov Link to this post

    How can I force new item to be saved before user clicks "add new" again. Sometimes user press "add new" by accident and the data will be lost.
  2. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 10 Nov Link to this post

    Hello Auvo,

    Do you use Batch editing mode?
    http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/batch-editing/defaultcs.aspx

    Batch editing is a tad specific. You can check the following post for further clarification on Batch editing. There is also sample for external save button implementation:
    http://www.telerik.com/forums/radgrid-within-dataform#n5vi8Bq46UaeI2H-tURExg

    To wrap it up - the postback to the server should be initiated only by the saveChanges method, which means that you should disable the AutoPostBack property of the button. Then, you can use the BatchEditCommand event handler provided by RadGrid and extract the changes. You can also can call any additional server-side logic within this event handler:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-editing/edit-mode/batch-editing/server-side-api

    For detecting and canceling the command action on client-side, you can check the provided explanation in the following post:
    http://www.telerik.com/forums/identify-the-button-clicked-in-batcheditcommand#vGZdD79bxkeyYMTYh_ycNg

    Here is a live sample with OnUserAction:
    http://demos.telerik.com/aspnet-ajax/grid/examples/data-binding/client-side/client-data-source-binding/defaultcs.aspx


    If you want to automatically save the changes before commencing some grid action, you should cancel the page, sort, filter, etc. events and then call the saveChanges method explicitly. After that, you can use the FireCommandEvent method on the server:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/control-lifecycle/how-to-fire-command-events

    In addition, I am also sending a sample RadGrid web site to demonstrate a similar implementation.

    I hope this will prove helpful.

    Regards,
    Eyup
    Telerik by Progress
    Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Auvo
    Auvo avatar
    34 posts
    Member since:
    Jul 2011

    Posted 10 Nov in reply to Eyup Link to this post

    Hi Eyup,

    I am using Editform.

    I want to cancel the "add new" if there is new record which is not saved yet. I do not want to lose any data.

    Or Can I hide the "Add new" and bring it back to visible when new record is saved?

  5. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 15 Nov Link to this post

    Hi Auvo,

    Yes, you can achieve both of these implementations. The first one can be achieved using some custom validation, similar to the approach demonstrated in the attached application.

    The other can be achieved by accessing the Add new record and hiding it explicitly when the row is opened in edit mode.

    Regards,
    Eyup
    Telerik by Progress
    Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Back to Top