I'm coding a Web Form using VS 2005 and ASP.Net 2.0. On the form, I have a GridView which shows existing records from a table and a DetailView always set to "Insert" mode to allow users to add new records.
So, the default mode for the DetailView control is set to Insert, and I'm just using the DetailView's "New, Insert, Cancel" Control field. That works fine in that the records get inserted correctly. However, what I really want to do is display a message box that says.
"Okay to insert this record?" with the standard "Yes/No" or "OK/Cancel" message box buttons.
The "No" or "Cancel" button needs to stop the insert from taking place. The "OK" or "Yes" needs to allow the insert to continue.
I had a similar situation with the GridView and the "Delete" button. In that case, I was able to turn the Delete Button into a Template Field, and add an Client Onclick event that's coded:
return confirm ('Okay to delete this record?')
That works fine because it's one regular link button and the commandName is 'Delete', which tells asp.net how to handle the event.
However, I'm not sure how to turn this sort of double "Insert, Cancel" dataview command into a template field, and even if I could, I'm not sure if it needs to be two buttons or what kind of CommandName(s) to use.
So, it's basically really simple . . .
I want the user to confirm that they really want to insert the record they just said they wanted to insert before I go ahead and actually add it to the database.
How do I do that using a DetailView control?
That works really well. However, I can't figure out how to turn that into a "Yes/No" type of confirmation box, or how to get the results of the user's choice (Yes or No) back into my server side subroutine to set "e.Cancel = true" and exit or to continue on, or even if I need to do that.
Please let me know.