Below are the deletion part of my current code for the forummanagement.aspx.cs:
if (checkIfPendingForumExists())
{
try
{
SqlConnection con = new SqlConnection(strcon);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("DELETE from forum_pending_tbl WHERE forum_id='" + TextBox1.Text.Trim() + "'", con);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert('Forum Deleted Successfully');</script>");
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "');</script>");
}
}
else
{
Response.Write("<script>alert('Invalid Forum ID');</script>");
}
This is the updated code for forummanagement.aspx:
<div class="col-4">
<asp:Button ID="Button2" class="btn btn-lg btn-block btn-danger" runat="server" Text="Delete" ButtonID.OnClientClick='return confirm("Are you sure you want to delete this item?");' />
</div>
After the updated buttonId.onclientclick suggested: there was error showing this:
Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: The server tag is not well formed.
Source Error:
Line 146: </div>
Line 147: <div class="col-4">
Line 148: <asp:Button ID="Button2" class="btn btn-lg btn-block btn-danger" runat="server" Text="Delete" ButtonID.OnClientClick='return confirm("Are you sure you want to delete this item?");' />
Line 149: </div>
Line 150: </div>
Source File: /adminforummanagement.aspx Line: 148
As you can see, I haven't able to ask the user to confirm the deletion first before actually directly deleting it because i'm not sure how to do that. Is there some kind of Response."something" that can be used to confirm the deletion. I may not know the syntax for that code or the response.write be written differently to get the use input Y or N? Im very new to asp.net and hope i can get any Help which would be appreciated.
Im using Asp.net web application (.NET Framework) c# as my project.
Your button has the error Parser Error Message: The server tag is not well formed.
Your markup:
<asp:Button ID="Button2" class="btn btn-lg btn-block btn-danger"
runat="server"
Text="Delete"
// error here:
ButtonID.OnClientClick='return confirm("Are you sure you want to delete this item?");' />
you only need OnClientClick
, without ButtonID
:
<asp:Button ID="Button2" class="btn btn-lg btn-block btn-danger"
runat="server"
Text="Delete"
OnClientClick='return confirm("Are you sure you want to delete this item?");' />