I have return one Javascript function which asks the confirm message to the user.
The JavaScript functions is
function ConfirmOnDelete() {
if (confirm("Are you sure to delete?"))
return true;
else
return false;
and GridView is like below:
<asp:CommandField HeaderText="Delete" ShowDeleteButton="True" />
Here I want to call the JavaScript function when user clicking the Delete in the GridView Command Field.
How to call this?
Assuming you want to keep using your
CommandField, you could do this programmatically using your GridView’sOnRowDataBoundevent.Specify the event handler for the RowDataBound event in your
GridViewdeclaration:Then in your event handler (code-behind) find your button (here I’m assuming
ImageButton, though this depends on yourButtonTypeproperty in yourCommandField) and add JavaScript to itsOnClientClickproperty.In the above example, cell refers to the column index of your
CommandFieldand ctrl refers to the control index (Delete button) within the cell you’re referencing.