Display cautionary message upon the deletion of a row from a gridview in asp.net

I have implemented a gridview on my web form that includes a command field for delete and edit functionalities.

My goal is to display a javascript alert message when a user clicks on the delete button:

Are you sure you want to delete this record?

If the user confirms by clicking 'Yes', then the record will be deleted.

Could someone advise me on how to achieve this functionality?

This is the current setup of my command field:

<asp:CommandField ButtonType="Image" 
     CancelImageUrl="~/styles/img/cancel.png" 
     DeleteImageUrl="~/styles/img/trash.png" 
     EditImageUrl="~/styles/img/edit.png" 
     ItemStyle-Width="50px" 
     ShowDeleteButton="True" ShowEditButton="True" 
     UpdateImageUrl="~/styles/img/update.gif">

Answer №1

If you want to link the Delete button to a JavaScript function, make use of the OnClientClick property.

<asp:Button ID="deleteButton" runat="server" CommandName="Delete" Text="Delete"
OnClientClick="return confirm('Are you sure to delete this record?');" />

For more information, check out this link.

Answer №2

To proceed with the deletion, please use the following code snippet:

<asp:LinkButton ID="lbtnDelete" runat="server" CommandName="delete" 
Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this record?');" 
CommandArgument='<%#Eval("ID") %>'>
</asp:LinkButton>`

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to begin the previous project on my Mac, but it functions properly on Windows

After running npm i, I encountered the following error message which I am unsure how to resolve. I tried reinstalling Node.js, Python, and Pyenv, but the issue persists. Interestingly, the same version of Node.js on Windows runs the project without any p ...

How should res.render() and res.redirect() be properly utilized within Express framework?

I am struggling to understand the difference between res.render('viewname', {msg: 'Message' }) and res.redirect('route') The render function allows you to pass a "message", but the redirect function does not. However, ther ...

When troubleshooting the "Uncaught reference error: require is not defined," the browserify command encountered the error message "Error: Cannot find module."

I am encountering a similar issue to @RachelD in the thread discussing the Uncaught reference error. When I execute the 'browserify' command following the instructions provided here, and using my directory as a reference, like so... myname@compn ...

Tips for displaying a modal within a modal in React

Currently, I have two components with modals. My goal is to open one modal from a button in the other component but clicking the button only closes the current active modal and doesn't open a new one. //Modal 1 <div className="modal fade" ...

calendar input type for both internet explorer and firefox

I frequently utilize the input type calendar on my website's intranet, but unfortunately, it only seems to work properly in Google Chrome and not in other browsers. As a solution, I have developed a code for a CSS/JavaScript calendar that I would like ...

Transferring retrieved information from one division to another

This snippet of code demonstrates the process of fetching names from a MySQL database using PHP and Ajax. Updated Code index.php <html> <head> <script language="javascript"> function showresult( ...

Issue with Angular Route Guard - Incorrect redirection to login page

I'm encountering an issue with my Angular app where even after the JWT token has expired, I am still able to navigate within the application without any API data being accessible. I've double-checked my setup and it seems right, but for some reas ...

Connect information to DropdownList within GridView asp.net

I have a web form that includes a GridView along with several controls within the GridView. One of these controls is a DropDownList located in the EditItemTemplate of the GridView. I am trying to bind this DropDownList using a method in my CodeBehind file ...

ReactJS Error: Rendering objects as a React child is not supported. If you intended to render multiple children, make sure to use an array instead

customMovieService.js: const films = [ { _id: "5b21ca3eeb7f6fbccd471815", title: "Inception", genre: { _id: "5b21ca3eeb7f6fbccd471818", name: "Sci-Fi" }, numberInStock: 8, dailyRentalRate: 2.0, publishDate: "2019-07-15T14:36:40.8 ...

Automated tools and frameworks for the testing of website performance

Hello, I have a website that heavily relies on AJAX for server communication. I am looking to conduct performance and stress testing using automated scripts. Can you provide any suggestions or recommendations? I am specifically interested in the functiona ...

Leverage external libraries in Angular

I discovered a library that I want to incorporate into my app: https://www.npmjs.com/package/jquery-animated-headlines However, I am struggling with the process of importing it. Firstly, I have added these lines in my angular-cli.json: "styles": [ . ...

What are some common applications of JSON?

Can you explain the purpose of JSON in Javascript and PHP and when it is necessary to use a JSON method? I checked out the link below but couldn't find any information on how JSON is implemented in actual projects. http://www.json.org/js.html ...

Interactive Content Swapping: How to Use Javascript for Dynamic Link Updates

http://jsfiddle.net/bUjx7/42/ <script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'> </script> <script type='text/javascript'> $(document).ready(function () { $('.fieldreplace ...

Tips for resizing a Textbox by dragging in asp.net?

Is there a way to dynamically adjust the size of a Textbox by dragging it in an ASP.NET application during run-time? ...

Using .after() in AngularJS for nested ng-repeat recursive iteration

I have a straightforward layout function adjustLinks($scope) { $scope.links = [ { text: 'Menu Item 1', url: '#', },{ text: 'Menu Item 2', url: '#' ...

A step-by-step guide on implementing a callback function

I am eager to incorporate a callback into this script - specifically the third callback onSlideChangeStart(swiper) found at http://idangero.us/swiper/api/#.V9CMp5grJlY. Since I have never worked with callbacks before, I am unsure of where to begin. In es ...

Passing parameters from JavaScript to a PHP class and sending the response back to JavaScript: A comprehensive guide

I am attempting to utilize a PHP Class along with JavaScript, but I need to adjust the class in order to pass a parameter to it. Since my knowledge of PHP is limited, I am unsure how to accomplish this. The class provided below uses a static variable $si ...

The keyboard fails to open when trying to input text on a WKWebView

Is there a way to programmatically open the keyboard in a WkWebView for tel text input after a JavaScript function call? I want the keyboard to display for efficiency reasons when a certain input is activated, but it doesn't gain focus automatically. ...

Using Conditions in AngularJS: Choosing Between Callbacks and Promises in a Service

I am currently faced with a specific scenario where I am uncertain whether to implement a callback or a promise. As someone who is relatively new to promises and just beginning to grasp their concept, I want to avoid falling into any potential anti pattern ...

Encountering Uncaught Error: Syntax error when calling Sizzle in Rails 4 with unknown expression [path_name]

We're currently in the midst of a Rails 4 project where users are required to log in and sign in through modals. Upon clicking the link to open the modal, an error reminiscent of this one pops up: https://i.sstatic.net/SWqtd.png Here's an exam ...