I'm struggling a bit with understanding how server-side deletion works. I know how to use MessageBox, but it's not the best approach. I've been advised to use a popup on the server side.
What I'm trying to achieve is that when you click the button, a popup should appear asking if you are sure you want to delete something. If yes, then delete based on C# events. If no, cancel the deletion. How do I work with both JavaScript and C#?
I encountered a problem where clicking the button triggers the popup, and when I click yes, it deletes successfully. However, when I click no, it still deletes. How do I handle yes and no in C# or Javascript? I have no idea how to go about this.
Your sample code would be greatly appreciated for me to understand better. Thank you!
Javascript
<script type='text/javascript'>
var result = confirm("Do you Want to Delete?");
if (result)
{
//do ajax call and delete from database
return true;
}
else
{
return false;
}
ASP.NET
<asp:Button runat="server" OnClick="btnDelete_Click" OnClientClick = " return confirm();" />
C#
protected void btnDelete_Click(object sender, EventArgs e)
{
//Delete operation
}