Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9091357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:35:26+00:00 2026-06-16T22:35:26+00:00

<script type=text/javascript> jQuery(document).ready(function () { // note: the `Delete` is case sensitive and is

  • 0
<script type="text/javascript">
    jQuery(document).ready(function () {
        // note: the `Delete` is case sensitive and is the title of the button
        var DeleteButtons = jQuery('#<%= gvShoppingCart.ClientID %> :button[value=Delete]');
       DeleteButtons.each(function () {
           var onclick = jQuery(this).attr('onclick');
           jQuery(this).attr('onclick', null).click(function () {
               if (confirm("Are you sure you want to delete item from shopping cart?")) {
                   return onclick();
               }
               else {
                   return false;
               }
           });
       });
   });
</script>

How can I change the above code to return the method below if true (instead of onclick())

 protected void gvShoppingCart_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        //code here
    }

EDIT: new code below –

 <script type="text/javascript">
     jQuery(document).ready(function () {
         $('.deleteStyle').click(function () {
             return confirm("Are you sure you want to delete");
         });
     });
</script>
<style type="text/css">
    .deleteStyle
    {
    }
</style>

Gridview Delete:

<asp:CommandField ControlStyle-CssClass="deleteStyle" ShowDeleteButton="True" ButtonType="Button"   />

gvRoles_RowDeleting (Note I am testing it out on Roles Gridview Now!)

protected void gvRoles_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        BusinessLayer.Roles rls = new BusinessLayer.Roles();
        rls.deleteRole(rls.getRole(gvRoles.DataKeys[e.RowIndex].Value.ToString()));
        this.BindRoles();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:35:27+00:00Added an answer on June 16, 2026 at 10:35 pm

    If you’re determined to use jQuery here’s a simple example:

    Example 1:

    Please note for this example you should remove ButtonType="Button" from the CommandField

        <script type="text/javascript">
            jQuery(document).ready(function () {
                $('.deleteStyle').click(function () {
                    return confirm("Are you sure you want to delete item from shopping cart?");
                });
            });
        </script>
        <style type="text/css">
            .deleteStyle
            {
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:GridView ID="gvShoppingCart" runat="server" OnRowDeleting="gvShoppingCart_RowDeleting">
                <Columns>
                    <asp:CommandField ControlStyle-CssClass="deleteStyle" DeleteText="Delete" ShowDeleteButton="true" />
                </Columns>
            </asp:GridView>
        </div>
        </form>
    </body>
    

    Example 2:

    This example shows you how achieve the same functionality using ButtonType="Button":

    Just change the grid view id’s to the required value;

    <script type="text/javascript">
        jQuery(document).ready(function () {
            jQuery('#<%= gvShoppingCart.ClientID %> :button[value=Delete]').each(function () {
                var onclick = jQuery(this).attr('onclick');
                jQuery(this).attr('onclick', null).click(function () {
                    var gridViewName = "gvShoppingCart";
                    if (confirm("Are you sure you want to delete item from shopping cart?")) {
                        var deleteItem = onclick.replace("javascript:__doPostBack('gvShoppingCart','", "");
                        deleteItem = deleteItem.replace("')", "");
                        __doPostBack('gvShoppingCart', deleteItem);
                    }
                    else {
                        return false;
                    }
                });
            });
        });
    </script>
    
    <asp:CommandField ShowDeleteButton="True" ButtonType="Button" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code to load in content: <script type=text/javascript> jQuery.noConflict(); jQuery(document).ready(function(){ jQuery('.content-div').load(all-events.html);
i have a jquery post like that <script type = text/javascript > $(document).ready(function() {
#!/usr/bin/perl print Content-type: text/html \n\n; print qq(<html> <head> <script type=text/javascript src=/jquery.js></script> <script> jQuery(document).ready(function(){ jQuery(#form_lang).submit(function(e){
<html> <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> <title>Untitled Document</title> <script type=text/javascript src=jquery.js></script> <script type=text/javascript
I have this code <html> <head> <script src=jquery-1.7.2.min.js type=text/javascript></script> <script src=jquery-ui-1.8.20.custom.min.js type=text/javascript></script> <script type
I have the following jQuery script running on my page: <script type=text/javascript charset=utf-8 src={{
I have this simple jQuery code $(document).ready(function() { $('#test').attr('value','hello world'); $('#test1').text('hello world'); }); And
Here is fragments of my HAML view: %script{:type => text/javascript, :src => assets/application.js} :javascript
I have a jQuery script: $.ajax({ url: /scripts/secure/development/ajax.asp, type: POST, dataType: text, data: cmd=addresses,
I have this jQuery script var dataString = class_id=+class_id; $.ajax({ type: POST, url: page.php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.