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

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

  1. 888 Casino Login Mobile Reviews Italy Non si può mai sbagliare se si decide sul casinò online. Dal momento che le tue possibilità di vincita sono più alte e hai il controllo sui tuoi account, sarai sicuro che tutto può essere al di sotto della gestione. Non c’è sentimento più alto di quello di essere sotto la gestione.

  2. Crypto Soft Bewertung : Ein durchschnittlicher Bullion Händler Gebühren in der Regel überall von vielen Prozent zu fortypercent oder zusätzlich über Wert. (in nur ein bisschen werde ich Ihnen zeigen, wie Sie Sie für 0P. c über Wert zu kaufen. Wirklich. Bleiben Sie dran.) Um den Listenwert einer numismatischen Münze zu ermitteln, werden die Münzen durch Benotungs Dienste benotet. 3 der am meisten Benotung Dienstleistungen sind; ANACS, PCGS und NCG.

    Visit cryptosoftbewertung

  3. i will practice it in my site. thanks for all

  4. Here the Indian Escorts in Dubai is out with the attractive look, sharp eyes and fine haircut that let the general population to men to appreciate such the services.

  5. Advice.pk says:

    i really need that code. thanks for this information. If you want property, house plot in Bahria Enclave which is located in Islamabad then visit Advice.pk to get complete knowledge and details. Bahria Town Islamabad/ Rawalpindi are Pakistan’s number one housing schemes.

  6. Smart Bazar says:

    that’s very cool. your blog helped me a lot. please visit wSmartBazar.pk to get latest and cool women’s dresses by free home delivery.

  7. I have practice it and work. thanks for share it. send me email if you have another like this.

  8. It is really a nice and helpful piece of info. I am glad that you shared this helpful info with us. Please keep us up to date like this. Thank you for sharing

  9. We have a three-part technology to defend against chargebacks. Using our technology frees you up to concentrate on your business and keeps up your merchant account so that you can grow your business.

  10. adobe support number – Adobe is an American multinational software company which is well known for its creation of multimedia and creativity software products.

  11. Norton.com/setup Online Help – To enable this protection for your Windows or Mac PC, all you need to do is download, install and activate the Norton Setup. But, before you start with the downloading process, remember to uninstall the already installed security software or antivirus (if any) from your device. This is mandatory to avoid any software conflict issue.
    norton.com/setup

  12. http://www.webroot.com/safe – Activate Your Webroot Safe today by just visiting Webroot.com/Safe as installing Webroot is a snap.www.webroot.com/safe You may download, open, enter keycode & get protected by Webroot Com Safe.

    http://www.webroot.com/safe

    #reinstall_webroot #webroot_keycode #webroot_secureanywhere_keycode #webroot_antivirus #install_webroot_with_keycode

  13. Click and download norton.com/setup to install Norton antivirus on your computer.Activate your norton activation key for norton setup

  14. Get started with Norton Setup for norton security antivirus software for all around 360 security. Activate product key for norton.com/setup Office.com/Setup
    Norton.com/Setup

  15. McAfee.com/activate – McAfee Activate at http://www.mcafee.
    com/activate, enter your product key for mcafee.com/activate
    online. Get Started with McAfee Activation.

  16. Install Office Setup – Sign-in to you microsoft account and then Enter 25 digit alphanumeric office setup product key on country and language.click on next to start office installation.We are the best Office Setup in US, Canada and Australia. At Office Setup, we put high effort, moderate IT answers for organization’s, and people.Whether set up or beginning, equipment or programming, system or electronic, we have something for each financial plan. officeplus.net is the exchanging name of Spacesolutions Pvt Ltd situated in California, USA. We are not Microsoft. However we are trained professionals to provide technical support for We are the world’s biggest innovation wholesaler and a main innovation deals, showcasing and logistics organization for the IT business around the world. Our people group based ethos, focused costs and nature of administration settles on Office Setup the right decision for your IT needs .Whether you are a learner or experienced in IT our courses are altered to furnish you with the key achievement criteria to thrive in future attempts.
    http://www.office.com/setup

  17. Happy wheels says:

    Thank you for giving post here and telling everyone else knows
    http://www.kizi10player.com

  18. office setup says:

    Sometimes Microsoft Office users face the issues after upgrading their Windows operating system. If you are also facing such type of issues related to your Microsoft Office setup installation then contact us at office.com/setup for the best support.
    office.com/setup

  19. Thanks for sharing such a great information with us. Your Post is very unique and all information is reliable for new readers. Keep it up in future, thanks for sharing such a useful post. Our toll-free number is accessible throughout the day and night for the customer if they face any technical issue in BROTHER PRINTER Call us +1888-621-0339 Brother Printer Support USA Brother Printer Customer Care Number

  20. This Australia assignment help is one of the world’s driving suppliers of scholastic help to understudies of all age and instructive levels.

  21. arjun singh says:

    Hello! This is my first visit to your blog! This is my first comment here, so I just wanted to give a quick shout out and say I genuinely enjoy reading your articles. Your blog provided us useful information. You have done an outstanding job.
    malaysia visa for indians

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>