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

Obtaining new record id on grid insert for uploaded records

1 Answer 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 29 May 2013, 05:44 PM
Hi I'm trying to work out if I can do the below.  Any advice on this would be helpful.

The short version

Can the AsyncUpload FileUploaded event be delayed till after an insert of a new record in order to obtain the newly inserted records id?

The long version

The scenario :

I have a db table which contains appointments.  An associated attachments table contains any files that are related to a particular appointment.

I'm using a bound radgrid which shows all appointments (using an entity data source with automatic inserts/updates). 
I want to allow the user to create a new appointment and as part of this allow attachments to be uploaded along with the new appointment. 
I insert the attachments into an attachment table and associate the attachments with the appointment by the appointment id.

The issue :

The issue  is that at the point of inserting the new appointment I am also inserting my attachment files (using RadAsyncUpload1_FileUploaded).  I require the appointment id at the point of inserting the attachments.  The appointment id is only generated on insert of the new record.

I stepped through the code and the FileUploaded triggers before the entitydatasource insert.

So I will have to insert the attachments with no associated appointment id.

On inserting the new appointment I would then have to update the attachments table and identify these new attachments, then associate the appointment id with them.  This seems very prone to potential errors.  The ideal solution would be if I can perform the entitydatasource insert before the file uploaded triggers as then I should be able to obtain the new appointment id and associate the new attachments records with this correctly.

Any suggestions on how to approach this problem would be appreciated. 

I can if necessary not allow uploads on the initial insert of the appointment.  Then if the user has attachments to upload they must edit the appointment and upload them at that point.  Uploading of the files when an appointment is edited is working correctly.

Thanks.

1 Answer, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 03 Jun 2013, 01:45 PM
Hi Michael,

This behavior is expected because all the information should be collected before inserting the new item. On the other hand when edit command is fired the item values are get from the data source in order to be displayed on the page. If you hook on UpdateCommand event you will notice that FileUploaded event is fired before it as when inserting.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Share this question
or