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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:31:31+00:00 2026-05-23T05:31:31+00:00

I am using an ASP datagrid, and I have a ButtonColumn. When the button

  • 0

I am using an ASP datagrid, and I have a ButtonColumn. When the button is rendered to the page, it is a input of type submit. So its a submit button. The button is used for deleting records. But I want to have some javascript that confirms that the user wants to delete the record. The problem that I have is that even if I return false from the confirm method, the submit event still happens…

Here is the Server Side Code that assigns the javascript method to the click event:

Button deleteButton = e.Item.Cells[6].Controls[0] as Button;
if (deleteButton != null)
{
    deleteButton.OnClientClick = "confirmDelete()";
}

Here is the ASP.net code that creates the datagrid:

<asp:DataGrid 
    runat="server" 
    ID="UsersList" 
    OnItemCommand="UsersList_ItemCommand" 
    AutoGenerateColumns="false"
    HeaderStyle-CssClass="dataTableHeader" 
    Width="60%">
    <Columns>
        <asp:HyperLinkColumn DataNavigateUrlField="Username" DataTextField="Username" HeaderText="Username"  DataNavigateUrlFormatString="~/Account/EditUser.aspx?user={0}"/>
        <asp:BoundColumn DataField="Email" HeaderText="Email" />
        <asp:ButtonColumn Text="Delete" HeaderText="Delete" ButtonType="PushButton" CommandName="DeleteUser" CausesValidation="false" />
    </Columns>
</asp:DataGrid>

Here is the Javscript code that confirms the delete:

<script>
    function confirmDelete() {
        var x = confirm("This action cannot be undone. Are you sure you want to delete this user?");
        return x;
    }
</script>

Perhaps there is no way to accomplish this with a ButtonColumn. I’m considering changing to a TemplateColumn, and just putting a button in there. But then I will have to redesign the code that handles these click events on the back end, which is currently handled in the ItemCommand handler.

  • 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-23T05:31:32+00:00Added an answer on May 23, 2026 at 5:31 am

    You need to confirm delete on form.submit(), not deletebutton.click(), but you’ll need to either assign an anonymous validation function to form.submit by the deletebutton.click(), or set a delete flag on deletebutton click, then check that value on form.submit(). That way other buttons that you WANT to submit the form still submit. And don’t forget to clear the variable/or anon function after validation fails.

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

Sidebar

Related Questions

I've created a Column button in datagrid using this code <Columns> <asp:ButtonColumn Text=Resend ButtonType=PushButton
Using ASP MVC and Entity Framework. In the view, you have a page declaration
I am using asp.net 2.0 and c#. I have a datagrid in which I
I am using one DataGrid with templatecolumn of Asp:Label Control. In Design Page i
Using ASP.NET ... I have an email button on a popup extender and would
I am using datagrid and I have a <asp:TemplateField> I have passed some parameters
I have a large dataset and datagrid on my asp.net page. I am going
Using asp.net, I need to generate a snapshot of an youtube video. I have
Using ASP.Net MVC on my Site.Master I have: <head runat=server> <title><asp:ContentPlaceHolder ID=TitleContent runat=server />
Using ASP.NET 3.5 and jQuery UI. When a user clicks the Search button, a

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.