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 3309660
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:40:03+00:00 2026-05-17T21:40:03+00:00

I have a TemplateField in a GridView in an UpdatePanel with a button called

  • 0

I have a TemplateField in a GridView in an UpdatePanel with a button called btnDelete. Rather than the standard OnClientClick="return confirm('Are you sure?')" I’d like to use jQuery Dialog.

So far, I’m able to set the jQuery using btnDelete.Attributes["onclick"] and setting the jQuery Dialog code in the code-behind. However, it posts back to the server in all cases before I have a chance to click “Confirm” or “Cancel”.

Here is the HTML it produces:

<input type="submit" rel="Are you sure?" class="action-link delete" id="ctl00_c1_gvTransfers_ctl02_btnDelete" onclick="return function() { 
            $('#delete-transfer-confirm').dialog({
              buttons: {
                'Confirm' : function() { $(this).dialog('close'); return true; },
                'Cancel'  : function() { $(this).dialog('close'); return false; }
              }
            });

            $('p.message').text($(this).attr('rel'));
            $('#delete-transfer-confirm').dialog('open');
          };" value="Delete" name="ctl00$c1$gvTransfers$ctl02$btnDelete">

What am I doing wrong that is causing this function not to block until either button is clicked?

Conversely, the standard confirm works just fine:

<input type="submit" class="action-link delete" id="ctl00_c1_gvTransfers_ctl02_btnDelete" onclick="try{if (!window.confirm('Are you sure?')){return false;};}catch(e1){alert(&quot;Unexpected Error:\n\n&quot; + e1.toString());return false;};" value="Delete" name="ctl00$c1$gvTransfers$ctl02$btnDelete">

Thanks,
Mark

UPDATE:

Ultimately, I had to use UseSubmitBehavior=”false” to get the name=”” attribute to render. Then I had to override the OnClientClick, setting the value to “return;” so the default __doPostBack() doesn’t get executed. Then I was able to wire up a .live() click handler, which invokes the __doPostBack() on Confirm:

$('input.delete').live('click', function(e) {
        var btnDelete = $(this);
        alert($(btnDelete).attr('name'));
        e.preventDefault();


        $('#delete-transfer-confirm').dialog({
          buttons: {
            'Confirm': function() {
              $(this).dialog('close');
              __doPostBack($(btnDelete).attr('name'), '');

              return true;
            },
            'Cancel': function() {
              $(this).dialog('close');
              return false;
            }
          }
        });

        $('p.message').text($(this).attr('rel'));
        $('#delete-transfer-confirm').dialog('open');
      });
  • 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-05-17T21:40:03+00:00Added an answer on May 17, 2026 at 9:40 pm

    Check the selected answer for this question for an example: How to implement "confirmation" dialog in Jquery UI dialog?

    A couple of notes:

    Don’t put your onclick functionality in an onclick attribute. One of the great benefits of jQuery is that it allows you to do Unobtrusive Javascript. Instead, do something like this:

    $(function() {
        $('.delete').click(function(e) {
            e.preventDefault() //this will stop the automatic form submission
            //your functionality here
        });
    });
    

    Also, make sure that your dialog is instantiated outside the click event, so that it is initialized before the first click event happens. So, something like this would be your result:

    $(function() {
         $("#delete-transfer-confirm").dialog({
          autoOpen: false,
          modal: true
        });
    
        $('.delete').click(function(e) {
            e.preventDefault();
            $('#delete-transfer-confirm').dialog({
                buttons: {
                    'Confirm': function() {
                        $(this).dialog('close');
                        return true;
                    },
                    'Cancel': function() {
                        $(this).dialog('close');
                        return false;
                    }
                }
            });
    
            $('p.message').text($(this).attr('rel'));
            $('#delete-transfer-confirm').dialog('open');
        });
    });
    

    That should do the trick for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an UpdatePanel containing a GridView which contains a button in the HeaderTemplate
I have a gridview inside an updatepanel. It has a TemplateField column with radiobutton:
I have a Gridview with ImageButtons added to a column via a templatefield. I've
I have a gridview that I have added a checkbox column using a templatefield
I have a button inside of a gridview's template field. Onclick i want to
I have a gridview within an updatepanel which allows paging and has a linkbutton
I have the following gridview that is inside an updatepanel: <asp:UpdatePanel ID=UpdatePanel1 runat=server> <ContentTemplate>
I have the folling Gridview column <asp:TemplateField HeaderText=Installed Date SortExpression=install_date> <EditItemTemplate> <asp:TextBox ID=gvtxtInstalledDate runat=server
In a gridview I have the following Template Field containing a textbox <asp:TemplateField ShowHeader=true
I have a gridview that i would like to show or hide a text

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.