Adding a Confirm Javascript PopUp to a ASP.NET GridView

The more and more I use the GridView control, the more I end up writing my own

rather then using the DataBound columns because of the additional flexiblity you get when writing your own templates.

This time I ended up writing my own TemplateField because I need to add a confirm pop up to basically a “delete” command (it didn’t really delete the database record but in fact flagged it as a different type)… but you get the idea where this might come in handy. After all you don’t want users calling saying “Yeah, I just deleted something I didn’t mean to”. Instead you want to pop up a javascript box with a “Do you really want to do this…because I am not fixing it again!”

Unfortunetly the

doesn’t offer you an


event, so this is my work around.

Here is the basic Javascript code to pop up a confirm button.


      function confirmSubmit() {

      var agree=confirm(“Do you really want to mark this prospect as in the database?”);

      if (agree)

       return true ;


       return false ;



Now in your GridView->Column Tag add a

and your onClientClick attribute. This will call your Javascript function above and display a confirm popup to your users. You also must define a onClick event that points to a function that you will need to create for the server side processing of this request.



        <asp:Button ID=”btnCustomerExist”

        text=”customer exist”



        OnClientClick=”return confirmSubmit()”

        Width=”100″ />



If the user clicks “OK” on the popup, you will need to handle the server side processing. I tend to write my own Data Access layer to handle Selects and Deletes so for me it is pretty straight forward from here, I call a function and pass in the unique id from the database.

Public Sub CustomerAlreadyExist(ByVal sender As Object, ByVal e As EventArgs)

        Dim ProspectID As Int32


        Dim btnRemoveProspect As Button = CType(sender, Button)

        Dim grdRow As GridViewRow = CType(btnRemoveProspect.Parent.Parent, GridViewRow)

        ‘Get ID

        ProspectID = grdRow.Cells(0).Text

        ‘Instant Class

        myAddProspect = New AddProspect()

        ‘Removes from Prospect Table


        ‘Refresh Gridview

        Page_Load(sender, e)

    End Sub

The End Result

Of course this won’t stop everyone from accidentally deleting users but it will stop 9/10.


A .NET, PHP, Marketing Guru authority, at least I hope I am. Reach me at

427 thoughts on “Adding a Confirm Javascript PopUp to a ASP.NET GridView

  1. Are you struggling with the hectic lifestyle or the competitive race of today’s world? Smart drugs like Waklert can help you in this regard. Waklert is one of the best known medications for the wakefulness and the cognitive abilities of the user. In fact Waklert is the strongest brain enhancers to hit the market. Buy Waklert online from Online Pharmacy Pills.

  2. Hi
    I read your post and found it quite interesting.
    The post you shared is very unique and informative.
    Thanks for sharing such a useful post.

  3. You should have clearly define topics which you want to learn and start collecting study material according to that topics. Also some assignment help service you can use to get knowledge as well. Just proceed accordingly and don’t waste your time because time is precious.

  4. Keto One Diet: Excessive weight has become a massive issue to everyone, men and girls alike. Given all the unhealthy effects of fats to the human body, it is definitely not right to require this issue without any consideration. However, you need a sensible deal of effort to be successful in living away with weight problems. The primary issue you wish to try and do is to interact in a very weightloss exercise.

    Visit Here :

  5. Jayspeech says:

    Thanks for sharing Popup side help to make the site. You provide important information. Our Company provide device for hearing and speech Thanks for guide good information. Thanks for sharing good information.

    speech therapy in patna

  6. navi verma says:

    Writing a diary post is avowedly necessary for growth of your websites.Thanks for sharing superb tips. Following this steps can work on the quality of your diary post in fact.
    Russian Call Girls in

  7. You should have clearly define topics which you want to learn and start collecting study material according to that topics. you can feel stuck and could not find ways to approach your assignments, but, you can always seek for assignment help.

  8. jon smith says:

    Online Pharmacy click here Pills is a very user friendly online medication shop. Our team is constantly working to give our customer best service. Total fourteen types of medicines for three different problems like pain, erectile dysfunction and cognitive enhancement. Our mission is to make medicines discover-able, affordable and understandable.So that you can know about online pharmacy pills. You can shop for all your medicines that you need from the comfort of your home or office.

  9. Mathew Anderson says:

    It is very interesting post, the information is very useful. Thank you for sharing such a amazing post.

  10. Slame Wood says:

    Nice post, thank you for sharing.

  11. Anthony Devis says:

    Hi, the post which you have provided is fantastic, I really enjoyed reading your post, and hope to read more. Thank you so much for sharing this post, I appreciate your work. |

  12. Alex William says:

    I Found your article very interesting and helpful.. Well explained, I really enjoyed reading your post, and hope to read more. Thanks for sharing this amazing information. | |

  13. Mcafee Antivirus Setup–Get started to McAfee Activate and finish establishment and initiation from on the web.

  14. Activate, Install, Download and Renew Your Product With Live Support. Setup Your Product, Activate Your Product, Install Your Product With 3 Setup.

  15. Alexa Beth says:

    Nice post. I was checking continuously this weblog and I am impressed!

    soma 500mg

  16. Office Setup, To Install MS Office a legitimate 25 character item key is required. Visit to sign in to office represent establishment.

  17. This is working properly

  18. Yepi Games says:

    Very interesting information I like this site very much so much superb information.

  19. Delveinsight says:

    Delveinsight team would like to thank you for the efforts. Amazing blog you have shared. I read it and get knowledge deeply. I learn so much new thing from here. If you are search competitive intelligence so you can visit now

  20. I really enjoy the blogs that you shared here deep and nice information shared here.

  21. – Learn how to download, install, activate, and uninstall Microsoft Office Setup on Mac and Windows. Activate your 25 character alphanumeric product key for Office 365, 2019, 2016, 2013, 2010, or Office 2007 at

  22. – You might have been looking for a proper guide that helps you in downloading, installing and activating the Norton Product key. Visit and proceed for the Norton installation setup. Get Norton help at Norton Customer support toll free number.

  23. Thanks for posting and discussion of the topic adding a confirm javascript popup to an grid view it’s a beautiful blog, and provide important topic so I really enjoyed this topic. Welcome to our company and provide the best services in SEO.
    Seo company in Patna

  24. This info very good its really very very informative great stuff post i appreciate your work..

  25. fantastic blog.. i think it’s very interesting and beneficial website for us.

  26. Thank you so much for providing great site. Keep it up more ..

  27. Go to to purchase, download, install, and activate Office 2019, 365, 2016 and many more. Enter You Office Product key on to activate your Office setup.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>