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

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

  1. This blog is providing beautiful news about about the Liberian Educational Sector. It is nice to know about it this is useful information. And such blogs makes us familiar with the whole world.

  2. Wonderful post. I appreciate your attention to this subject and I learned a good deal.

  3. I was looking for something like this…I found it quiet interesting, hopefully you will keep posting such blogs….Keep sharing.

  4. Online reading is not my thing. But after reading your blog I am really pleased. I don’t know about other blogs but this I will definitely keep coming back to.

  5. I really like your site.and really enjoyed this post.Very helpful,, the style of this article I’m like, really pretty good.

  6. nice blog,can you teach me how to creat it!

  7. Welcome our Coach Outlet stores,Coach is known to all that all the Coach handbags were designed for the customers who seek for the fashion.Coach Factory Outlet Store Offer Many beautiful Coach Outlet Online with the classic pattern that warmly welcomed by customers-40% are the most professional COACH online shopping mall, COACH products provide the latest offer, Coach purses pictures.

  8. Hi my friend! I wish to say that this post is amazing, nice written and include approximately all important infos.

  9. Very efficiently written post. It will be supportive to everyone who utilizes it, including yours truly :) . Keep up the good work – i will definitely read more posts….

  10. Click here says:

    OMG…This is just what I need. Flabuless where have you been the last ten years of my life? I need you. Thanks!

  11. Click here says:

    The article has really peaks my interest. I am going to bookmark your site and preserve checking for new information.

  12. Revenue nighttime trends other sorts of breakthroughs pick monthly payments mutually together with commonly encounter superior ingredient certification regarding ingredient value related to getting. Your own personal hard attained cash improve recognizing is usually coasted declare for example a wise part round the profits improve. Your individual current wise part coasted commonly relating to 2% mutually together with 4%. Quite a few playing cards organizations value obtaining a unveiled recognizing no matter what her or his training relating to another person’s cash items.

  13. What a excellent work you have post here Thanks.

  14. This conent is simply exciting and creative. I have been deciding on a institutional move and this has helped me with one aspect. surf camp Tenerife

  15. Both the MDI and Blue Hill tours are bi-annual events—in the off years, the Blue Hill Garden Club has a garden tour, and the Bar Harbor Club has a garden tour. So something in each town each knowledge

  16. Citing is one in every of the simplest strategies to stop plagiarism. To report methodology for carries with it the list details for any details or ideas you employ from sources, whether or not quoted or paraphrased.

  17. There square measure as several reasons to put in writing as there square measure writers. Every people have our own reasons why we tend to sit ahead of a keyboard or scribble our thoughts on a pad. Even so, there square measure some key reasons why you must frequently write. Whether or not its articles, essays, poems, compositions, papers, books, e-books, ad copy, literature or the other of the myriad of writing forms, it is a vocation that serves virtually everybody in sensible role. Here square measure seven sensible reasons why you must be a part of the good bequest of writers.

  18. This is such a great information for me, because i do an online job thats why i need fast Internet connection, i search how to bost internet speed then ireach at a right place. Boscovs coupons

  19. douchebak says:

    Great explanation about this topic and i am new guy to this job thanks to sharing the wonderful articles

  20. douchebak says:

    It is nice to read the information provided in your blog and i like this information because it is based on reality and i like this information. And it provides knowledge and useful information to the visitors of this site and i would like to visit this site again.

  21. ice to read the information provided in your blog and i like this information because it is based on reality and i like this information. And it provides knowledge and useful information to the visitors of this site and i would like to visit this sit

    Mr Locksmith is the most reputed emergency locksmith company
    in Toronto . We’ve assembled an all-star team of certified
    technicians that are on call 24/7. We are fully committed to
    a 25 minute arrival time. This means that you can always
    depend on us to be there for you. Our hard work and lightning
    fast arrival time has gained us a highly positive reputation
    among the local residents of the Toronto.

  23. Great web site you’ve got here.. It’s hard to find good quality writing like yours nowadays. I honestly appreciate people like you! Take care!

  24. locksmith says:

    ????? ?????

    ????? ????? ??? ???? ?? ????,
    ????? ?? ???? ????!???? ???? ???, ??? ???? ????? ????? ????? ???? ???? ????? —
    ?????.???????? ??, ??? ????, ???? ???? ?????? ??? — ??? ??? ????? ??? ????
    ???? ????? ???! ???? ?? ?????? ??? ?? ????? ????? ??????, ?? ??? ????, ???
    ??? ???? ?? ??? ???? ??! ?? ???? !!! ?????? ???% 10000000 ?????

    ?????? ?????

  25. I was looking for something else. The story and website you have distributed is extremely intriguing and informatics, Thanks for imparting such sort of informatics thing.

    Visit : Accredited High School Diploma

  26. Online GED says:

    It was nice to land on this website post and to see such superb stuff. Your website is choked with authentic and highly-researched knowledge that’s price reading. I’ll sure enough advocate your website to my fellows!

  27. stop smoking says:

    your site is very useful but still mission a pro logo you can use the logo creator

  28. stop smoking says:

    I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share.

  29. Weight loss recipes are abundant from all over the world and can help to spice up any dish. Here is a great, healthy weight loss recipe that will leave you feeling full and satisfied.

  30. I really enjoy examining on this internet site, it contains excellent articles.

  31. plak bh says:

    Great info. I love all the posts, I really enjoyed, I would like more information about this, because it is very nice., Thanks for sharing

  32. plak bh says:

    I can not stop reading this. And ‘so fresh, so full of information, I do not know. I’m glad that people actually write the smart way to show the different sides of him.

  33. Currently student’s life haven’t merely to examine & to pass their examination to graduate productively. Many them got to figure what is more therefore on provide university and for the living costs. One or two of students all the same have families, so as that they have in operation even further.

  34. Great web site you’ve got here.. It’s hard to find good quality writing like yours nowadays. I honestly appreciate people like you! Take care!

  35. I am definitely enjoying your website. You definitely have some great insight and great stories.

  36. Though I don’t understand anything about Java, I like this post.
    cheapest essay writing service

  37. We all present the typical divisibility rule to get a Divisor the prime amount and put it to use to certain cases. The explanation is lucid and an easy task to follow, comprehend and use. dolor de cabeza

  38. A forefather should always be in merciful well-life aparts stamina. For this he should receive up propitious in the lineage. He should permit gymnastics regularly.Harry and David coupons

  39. Thanks for the unmatchable was rale useful for me.navigator sharing specified ideas in the instant as symptomless.this was actually what i was labour for,and i am voluntary to came here!

  40. Good post you have shared here i like your work keep it up.

  41. I found your this post while searching for some related information on blog search…Its a good post..keep posting and update the information. lithium ion battery

  42. Sea buckthorn can be used to treat high blood pressure, high cholesterol, arthritis, eczema, inflammation and rosacea etc. Here let us talk about sea buckthorn as a home remedy for eczema emphatically.

  43. Annexum says:

    It seems like an educational blog which always some new information to visitors and Enjoying every little bit of it and I have you bookmarked to check out new stuff you blog post.

  44. Such as your post is very creative and fantastic.i am agree with you.i have club penguin codes its really nice work for generator codes and cheats codes for free of cost than visit here.

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>