[Last Call] Learn how to a build a cloud-first strategyRegister Now


ASP.Net 2.0 DetailView Insert User Confirmation Message Box?

Posted on 2006-05-25
Medium Priority
Last Modified: 2012-05-05

  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?

I'm already coding some stuff into the "ItemInserting" subroutine to make sure there are no blank values and a couple of other things, and I'm using a neat little "Alert" javascript routine I had help with here in Expert's Exchange:


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.

Any suggestions?

Please let me know.

Question by:klgrube
  • 3
  • 2
LVL 27

Expert Comment

by:Sammy Ageil
ID: 16774556
you have 2 option here

1- Download this control and try to use it or even rebuild it adding any new features you may need.

2- Build a popup control from a Div and use it as your confirm box with all server side code



Author Comment

ID: 16775719

   Thank you, as always!   But I don't speak C#, so I can't translate what I see there.  Also, there's some additional code later in the comments  where the javascript is partly converted to VB Script that helps with browser compatability  But, that doesn't look complete.  I can't quite interpret it.  And, there also seem to be some issues with ASP.Net 2.0 compatability.  So, this isn't going to work well for me.

   I'd love to try your second suggestion, however, if you could please point me to a small example where a simple standard little popup window is used as a substitute for a message / confirmation box.  I haven't been able to find one that works well with ASP.Net 2.0.

   In the meantime, although it may not have been clear, one major part of the question I'm asking is how to code an 'onclick' event into the 'insert' button of the DetailsView control.  I can't figure out how to access that part of the control (the DetailsView command field called "New, Insert, Cancel." )  I can't seem to be able to turn it into a template field, so I can't figure out how to add an on-click event.  That might be the best alternative, insead of writing my own popup control - or borrowing someone else's!  

   Any suggestions?  If that's simply not possible, please let me know.

LVL 27

Expert Comment

by:Sammy Ageil
ID: 16776368
I have used the same code in C# with asp.net 2.0 and it worked fine for me.
My idea of using custom control was about warpping a div control in a custom control "dll file" using Css classes to display and hide the control with a little bit of javascript to control the postback. unfortunately I have not seen any such control thats why I thought of creating it for my next project.
take a look here to see how to insert a record using the detailsview control

Good luck


Author Comment

ID: 16777133

   Thanks again!  

   I'm okay with knowing how to insert a row using a DetailsView.  What I still can't figure out, though, is how to get to an 'onclick' event in the combined  Insert/cancel control field used for inserts in the DetailsView, or how to turn it into a template field so I can get to an onclick event.

   Any suggestions?

LVL 27

Accepted Solution

Sammy Ageil earned 2000 total points
ID: 16778389
If you want to customize this row then instead of using the CommandField use a TemplateField where you define any or all of the ItemTemplate, EditItemTemplate or  InsertItemTemplate as required.

In each template you can add Buttons with the desired CommandNames for
each template.  For example, within the ItemTemplate, you would add:

<asp:Button Text="Edit" runat="server" ID="Edit"
<asp:Button Text="Insert" runat="server" ID="Insert"

In the EditItemTemplate, you would add:

<asp:Button ID="UpdateButton" runat="server" CommandName="Update"
<asp:Button ID="btnCancel" CausesValidation="false" runat="server"
CommandName="Cancel" Text="Cancel"></asp:Button>

and in the InsertItemTemplate you would add:

<asp:Button ID="btnInsert" runat="server" CommandName="Insert"
<asp:Button ID="btnCancel" runat="server" CausesValidation="false"
CommandName="Cancel" Text="Cancel"></asp:Button>

This would mimic the action performed by the CommandField (which renders all
those buttons for you based on which property you set to true.
Once you are in the edit template in the desiner you can double click on any button to get the click event
Note: I have not tried this myself but I dont see any reason why it shouldnt work

Good luck

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question