Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I want to delete a record from but I want a confirmation box before deleting.
Posted
Updated 3-Oct-10 22:03pm
v2
Comments
Dalek Dave 4-Oct-10 4:03am    
Minor Edit for Grammar.

function confirmSubmit(strName) {
    var agree = confirm('Are you sure want to delete this ' + strName  + '?');
    if (agree) {
        return true;
    }
    else
        return false;
}


you can call js function like below code.

<br />
<br />
<asp:LinkButton ID="Delete" CommandName="Delete" OnClientClick="return confirmSubmit('Category'); "<br />
                                CommandArgument='<%# Eval("CategoryID") %>' runat="server">Delete</asp:LinkButton><br />
<br />
 
Share this answer
 
Comments
Dalek Dave 4-Oct-10 4:03am    
Good Answer
<asp:LinkButton ID="Delete" CommandName="Delete"  OnClientClick='javascript:return confirm("Are you sure you want to delete?'   runat="server">Delete</asp:LinkButton> 
 
Share this answer
 
A simple googling you have given you the answer.
You can use Javascript for this .
<script type="text/javascript" language="javascript">
        function ConfirmOnDelete()
        {
          if (confirm("Are you sure?")==true)
            return true;
          else
            return false;
        }
    </script>



Then you can call that JS function like this:

<asp:button id="Button1" runat="server" text="Button" onclick="Button1_Click" onclientclick="return ConfirmOnDelete();" xmlns:asp="#unknown">

Or adding an attributes to the Button at code behind Page_Load event like:

Button1.Attributes.Add("onclick","return ConfirmOnDelete()");
Hope this helped you :)
 
Share this answer
 
Comments
AmbiguousName 4-Oct-10 10:06am    
Can you exactly tell that where this javascript code will be written? Will it be in Default.aspx or in Default.aspx.cs? thnx
Baji Jabbar 4-Oct-10 12:04pm    
Javascript code should be inside the head tag of Default.aspx , and Button1.Attributes.Add("onclick","return ConfirmOnDelete()"); code should be in the Default.aspx.cs page ( in page load)

It is recommended that you should write the javascripts in a .js file and then refer the file to the .aspx page

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900