如何在 asp.net Web 应用程序(.Net 框架)c# 中首先删除网站用户之前询问是或否?

How to ask yes or no before delete to the website user first in asp.net web application(.Net framework) c#?

下面是我当前代码的删除部分 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>");
}

这是 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>

更新后 buttonId.onclientclick 提示:显示错误:

解析器错误 说明:解析服务此请求所需的资源期间发生错误。请查看以下具体的解析错误详细信息并适当修改您的源文件。

解析器错误消息:服务器标记格式不正确。

来源错误:

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>

源文件:/adminforummanagement.aspx行:148

如您所见,我无法在实际直接删除之前要求用户先确认删除,因为我不确定该怎么做。是否有某种 Response."something" 可用于确认删除。我可能不知道该代码的语法或 response.write 的写法不同以获得使用输入 Y 或 N? 我是 asp.net 的新手,希望我能得到任何帮助,我们将不胜感激。

我使用 Asp.net Web 应用程序 (.NET Framework) c# 作为我的项目。

第 148 行你不需要包含下面的 ID 应该可以工作(也看看单引号和双引号的位置。你只需要来自 C# 端的 ID(代码隐藏)

<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?');" />

你的按钮有错误Parser Error Message: The server tag is not well formed.

您的标记:

<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?");' />

你只需要OnClientClick,不需要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?");' />