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

onClientClick

event, so this is my work around.

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

<SCRIPT LANGUAGE=”JavaScript”>

      function confirmSubmit() {

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

      if (agree)

       return true ;

      else

       return false ;

    }

    </SCRIPT>

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:TemplateField>

    <ItemTemplate>

        <asp:Button ID=”btnCustomerExist”

        text=”customer exist”

        Runat=Server

        OnClick=”CustomerAlreadyExist”

        OnClientClick=”return confirmSubmit()”

        Width=”100″ />

   </ItemTemplate>

  </asp:TemplateField>

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

        myAddProspect.RemoveFromDatabase(ProspectID)

        ‘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.

Tim

A .NET, PHP, Marketing Guru authority, at least I hope I am. Reach me at tboland@gmail.com

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

  1. I look for such article along time, today i find it finally. this post give me lots of advise it is very useful for me…limo rental Brooklyn

  2. I most likely appreciating each and every bit of it. It is an incredible site and decent impart. I need to much obliged. Great employment! You all do an incredible blog, and have some extraordinary substance. limo rental Brooklyn

  3. Friv says:

    I would very much like to agree with the previous commenter! I find this blog really useful for my uni project. I hope to add more useful posts later.
    http://www.kizi4games.org | http://www.friv11games.net

  4. I am glad it was an enjoyable experience for you. I think that you should definitely do it again sometime and hopefully I will be able to make it to that one.. https://www.allassignmenthelp.com

  5. 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!”

  6. ABOUT OPENING VARIOUS URL’S WITH THE SINGLE CLICK OF YOUR MOUSE BUTTON. THE FAST URL OPENER CAN HELP YOU ACHIEVE THIS GOAL AND SAVE YOU SOMETIME AND BOTHERATION OF CLICKING THE MOUSE KEYS AGAIN AND AGAIN, ENJOY THE WONDERS OF FAST URL OPENERAND SAVE TIME .

  7. Lisa Henry says:

    Here are the simple steps to add an email address to your Hotmail contacts
    Hotmail Login Now you can Send and Receive your Hotmail in your Gmail Account!
    Hotmail Sign In The process of creating your Hotmail account has been successful, you can use it right now. Good luck!
    Sign In To Hotmail I would like to share an article which details how to remove your Hotmail account simply and quickly as the way you sign in Hotmail.
    Recover Hotmail Password How to recover Hotmail password
    Create Hotmail Account How to create a Hotmail account
    Thanks for sharing nice information with us. i like your post and all you share with us is uptodate and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job!!!

  8. 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.
    open facebook | science kombat | science kombat game
    I have really liked your writeup.

  9. Thank you for sharing valuable information. Nice post. I enjoyed reading this post

  10. play here says:

    Numerous players shelter put in days and evenings gloomed-on to these Flash and Shockwave Games,

  11. as these help an uneven chance to play all the relentless parlor Games moreover some crisp ones,

  12. sitting at Home, being just the power bill and web association.

  13. Splash PRO says:

    An interesting discussion is definitely worth comment. There’s no doubt that that you
    should publish more on this topic, it may not be a
    taboo matter but typically people do not talk about such topics.
    To the next! Many thanks!!

  14. You are well said about it. Everybody’s Erasmus experience will be different as they feels. I have got a nice experience when using this. Hope this will improve all the features soon and will get lots of information about this. You can choose dissertation editing service for all kind of academic works.

  15. Very interesting blog. Alot of blogs I see these days don’t really provide anything that I’m interested in, but I’m most definately interested in this one. Just thought that I would post and let you know.
    facebook lite |resignation letter|qr code generator |

  16. Thanks a ton for sharing your knowledge! It is great to see that some people still put in an effort into managing their websites. I’ll be sure to check back again real soon.ecommerce website development

  17. Hi there to all, how is the whole thing, I think every
    one is getting more from this website, and your views are
    nice designed for new visitors.

  18. Ronn Ronn says:

    I would very much like to agree with the previous commenter! I find this blog really useful for my uni project. I hope to add more useful posts later.

  19. Make My Assignments|Assignment help make customized assignments. Our team of experts is ready to make your assignments 24×7. We provide 100% Plagiarism free work
    Make My Assignment

  20. Kizi 2016 says:

    We have the best free online games for you.
    Jogos Friv 2/
    Juegos Friv 4

  21. gta 5 says:

    Everyone loves what you guys are usually up too. Such clever work and exposure! Keep up the superb works guys I’ve added you guys to my own .

  22. Wow, fantastic blog layout! How long have you been blogging for? You make blogging look easy. The overall look of your site is excellent, let alone the content!

  23. excel says:

    Hello, I would like to subscribe for this webpage to obtain newest updates, so where can I do it please assist.

  24. There was a time, when I was having real trouble dealing with sudden uncertainties. However, with short term loans by Oyster Loans, I found a way out of the crisis. Open to almost all the applicants, these loans are indeed the best alternative to resolve temporary monetary crisis.

  25. Friv 1000 says:

    Please visit our website and play exciting games,thank you verry much
    Friv 2|
    HappyWheels

  26. Friv says:

    Very entertaining information. found a lot of things for Yourself Useful. Thx !!!
    Friv4

  27. Let’s keep are safe place to play the very best free games for kids! Please click:

    - juegos friv gratis

  28. Friv100 says:

    You’d have time to look these kids active. Please visit our website and let us play the games interesting.
    Thanks you for sharing !
    Friv 100
    Friv 8
    Friv 2

  29. Surtikart says:

    nice post to read

  30. GirlsGoGames says:

    You want to relax after a stressful working hours. Refer to our website. Hope you get the most comfort.
    Thanks for sharing !
    GirlsGoGames
    Kizi 100
    Frvi

  31. Loan Tube says:

    Loan Tube is a regulated and respected online broker in the UK and it fetches ideal deals on Short Term Loans UK. To know more about the loans and the offers.

  32. Hunting for honestly created reviews and ratings for android apps? Forget about your anxieties, we provide Android App marketers with impartially created reviews with elegant rating.

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>