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

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

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

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

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

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

  8. 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 Laser Printer
    Brother Printer
    Brother Printer Driver Download

  9. MS office Teams unites everything a group needs in a single place. You can coordinate the applications and administrations you require, including Office 365 applications like Excel or countless gathering applications. visit office.com/setup for Download, Installation and Activation Microsoft Office.
    http://officecomoffice.com/

  10. In case you wish to download and install the tool then you may need to visit the link norton.com/setup. The Norton 360 Antivirus helps you to detect, prevent and block the malicious sites or online threats. Here in this article, we will discuss the process to Unblock Website Norton 360 Antivirus.
    http://nortonnortoncom.com/

  11. Microsoft office setup is the full suite of Microsoft efficiency programming that joins an assortment of utilizations, administrations, and server like Excel, PowerPoint, Word, OneNote, Publisher and Access. Aside from the working frameworks, these projects are Microsoft’s key items that are generally utilized programming on the planet. Microsoft Office.com/Setup bundles all the best programming that Microsoft brings to the table. http://officecom-office.com

  12. office.com/setup, the popular productivity suite includes a number of servers, application, and services. office.com/setup has been developed for Windows, Mac, Android, and iOS operating systems. With office setup 365 as the latest version, the software is being widely used by the consumers and businesses.
    http://officecomusa.com

  13. Protecting your devices and managing your norton.com/setup product is as easy as adding a new device in your Norton account. Follow these instructions to install or reinstall your Norton product that is registered to your account.If you have received your Norton product from your service provider.
    http://nortoncomusa.com

  14. norton.com/setup-created and conveyed by symantec company, norton is an antivirus programming offering the customers and organizations endpoint assurance to ensure their advanced world.

  15. Positive site, where did u come up with the information on this posting? I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work.

Leave a Reply

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