This is a migrated thread and some comments may be shown as answers.

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

3 Answers 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Auvo
Top achievements
Rank 1
Auvo asked on 07 Nov 2016, 08:36 AM
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.

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 10 Nov 2016, 07:06 AM
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.
0
Auvo
Top achievements
Rank 1
answered on 10 Nov 2016, 08:05 AM

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?

0
Eyup
Telerik team
answered on 15 Nov 2016, 07:52 AM
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.
Tags
Grid
Asked by
Auvo
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Auvo
Top achievements
Rank 1
Share this question
or