As part of my current unpaid internship in C# and Asp.net, my employer has assigned me the task of implementing a JavaScript function to prompt the user for confirmation before deleting a record from the database.
After conducting thorough research, I successfully wrote the JavaScript function that notifies users about their intention to delete a particular record before proceeding with the action.
While the JavaScript function functions correctly, I now face the challenge of invoking the backend C# function responsible for actually removing the record from the database using the front-end JavaScript function I just developed.
Below is the code:
Javascript function:
function watchdelete()
{
if (confirm("Are you Sure You want to delete this Manufacturer?") == true)
{
__doPostBack('btnDelete_Click','');//"PageMethods.btnDelete_Click();
}
else { }
}
The frontend section which triggers the client-side JavaScript code attached to the delete button:
<asp:Button ID="btnDelete" runat="server" Text="Delete" OnClientClick=" return watchdelete()" OnClick="btnDelete_Click1" />
The backend C# function that needs to be called to delete the record from the database:
protected void btnDelete_Click(object sender, EventArgs e)
{
// Code simplified for clarity
}
Any suggestions or insights on how to tackle this issue would be highly appreciated. Thank you.