开发者

Confirmation delete window - deleting record when click delete or cancel

开发者 https://www.devze.com 2023-03-01 18:18 出处:网络
I have a Javascript file that contains the function for calling the confirmation delete window, the code used is similar to the following:

I have a Javascript file that contains the function for calling the confirmation delete window, the code used is similar to the following:

function Delete() 
{
    confirm('Delete this user');
    
}

I have a gridview with a template field that can delete a row in the gridview, this is a snippet of what I have:

<asp:TemplateField HeaderText="Amend" ShowHeader="false">
               <ItemTemplate>
                   <asp:LinkButton ID="btnedit" runat="server" 
            CommandName="Edit" Text="Edit" ></asp:LinkButton>
               </ItemTemplate>
               <EditItemTemplate>
                   <asp:LinkButton ID="btnamend" runat="server" 
            CommandName="Amend" Text="Amend" ></asp:LinkButton>
            <asp:LinkButton ID="btndel开发者_如何学运维ete" runat="server" 
            CommandName="Delete" Text="Delete" OnClientClick="return Delete() "></asp:LinkButton>
               </EditItemTemplate>
            </asp:TemplateField>

Within the aspx.vb page I have code to do the deletion of the record (this works fine), I have this code within the gridview property OnRowDeleting="RowDeleting1"

Protected Sub RowDeleting1(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
' code to do the deletion

When the confirmation of the delete appears (options are to delete or cancel), the deletion occurs when I click delete or cancel. Ideally I only want the deletion to occur when I click delete and just stay on the page when I click cancel, would anyone be able to advise what I am doing wrong?


Replace confirm('Delete this user'); with return confirm('Delete this user');


You can use Ajax Confirm Button Extender, with some modification to your code.

ex:

 <cc1:ConfirmButtonExtender ID="btn_Delete_ConfirmButtonExtender" runat="server" ConfirmText="Delete this user?"
             Enabled="True" TargetControlID="btn_Delete">
 </cc1:ConfirmButtonExtender>
0

精彩评论

暂无评论...
验证码 换一张
取 消