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

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

  1. Great sharing you have done here keep it up.

  2. Such an informative post you have shared with us,i really like your sharing.

  3. Its best way to get free clash of clans hack tool and clash of clans gems.

  4. The way that an outline is manufactured and masterminded can enormously affect the completion of the examination. In like manner concerning the people from the online paid reviews, it is their dedication to hold brisk to the marked standards set up for the association to most likely fill its need.

  5. In spite of the way that the title bank won’t approach you what the money is for, oversee yourself to not taking out an auto title progress pointlessly. With result expected in a month, these transient advances are best used for emergency costs. Take out exactly what you truly oblige so the portion is to a lesser degree a weight toward the end of the month term period.

  6. dewas says:

    Thanks a lot for sharing us about this update. Hope you will not get tired on making posts as informative as this. Clash of Clans generator

  7. On the other hand, a sensible title on the vehicle is the pivotal for such credits. This comparably helps in restoring the procedure of support of the advances. These advances are regularly speedier approve than the general credits.

  8. Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information.limo rental atlanta

  9. India Flower says:

    This is also a very good post which I really enjoyed reading. It is not everyday that I have the possibility to see something

    like this.

  10. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. Thanks…spiderman toys

  11. payday loans says:

    Individual you understand inside corporation. Quite possibly people keep in mind convening a friend of your buddy whom worked with a financing company. Or it could be people unclearly contemplate your buddy’s sibling will a thing with real-estate

  12. What you will utilize the cash for or why you oblige it so frantically are not conveys which apply to a vehicle title credit power. There are no meddlesome solicitation which apply to the reason behind the budgetary crisis.

  13. Thanks for useful information. Custom writing services are available at http://special-essays.com 24/7.

  14. With a touch of consistent quality, you ought to be able to discover distinctive certifiable affiliations offering the sorts of snappy money credit that you require and a brief while later you can be well on your approach to manage beating your brief money needs.

  15. Laura says:

    surely, your article is worth reading!thanks a lot!we can write your essay on the regular basis without delays.All the writers are creative professionals who can compose a quality worjk according to your need, wishes and an affordable price.

  16. Get top quality essay papers from the best academic writers!

  17. essays says:

    I did all as you write and it helps. Thanks a lot for the tips.

  18. A payday credit is to a degree transient change you can use to cover usage until your next payday. You can apply online and the choice to credit you the cash is made straight away. As a rule the entire application should be possible online and the cash lent can be credited into your financial alter around the same time as you make your application.

  19. In case you oblige money then get terrifying Visas and pay them on time to make your credit. Pay more than the base hole and usage them to pay bills so you can pay what you need to pay while making your credit.

  20. happy wheels says:

    Great! Thanks for sharing the information. That is very helpful for increasing my knowledge in this field.
    pacman
    happy wheels

  21. I enjoyed this article because it is not including worthless information . It’s a good occasion to express thanks for sharing article about the javascript.

  22. Greetings! I really enjoy your article, because i like the way you write and presenting your ideas. Your article about javascript is very useful and very understanding, because even I understand all. Thanks! I get to see more interesting stuff from you in future!

  23. osma says:

    Do you need a Loan?
    Are you looking for Finance?
    Are you looking for a Loan to enlarge your business?
    I think you have come to the right place.
    We offer Loans atlow interest rate.
    Interested people should please contact us on
    For immediate response to your application, Kindly
    reply to this emails below only.
    osmanloanserves@gmail.com

    Please, do provide us with the Following information if interested.
    1) Full Name:………
    2) Gender:………
    3) Loan Amount Needed:………
    4) Loan Duration:………
    5) Country:………
    6) Home Address:………
    7) Mobile Number:………
    8)Monthly Income:…………………
    9)Occupation:………………………
    )Which site did you here about us…………………
    Thanks and Best Regards.
    (osmanloanserves@gmail.com)

    www.(osmanloanserves@gmail.com)

  24. Professional writing service is one of those services ho cares about their customers. In our company works only experts who will write for you only best essay. Visit this service with no hesitations.

  25. happy wheels says:

    Thanks for the great post.

  26. onlineitguru says:

    Testing Tools Online TrainingTesting Tools Online Training at Online IT Guru with 10+ years of real time exp. trainer, Certification level Manual, QTP and QC training with placement also

  27. payday loans says:

    With a touch of consistency, you ought to be able to discover diverse good ‘ol fashioned affiliations offering the sorts of convenient money credit that you require and a while later you can be well on your approach to manage beating your brief money needs.

  28. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it ccsinternet.org

  29. Choosing a determine fundamental places to apprehend article shells, nearly numerous confidentials symbol-screen their allow chums pertaining to handles. Lecture Lib evidence be holy to gain varieds of streamer thorn customers who’re merry beside the ramifications the street made processs too in scope they extra on putting warmhearted fresh petitions in supplement to bettering their agree qualities forward the other. ccsinternet.org

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>