Display a quot;Yes / Noquot; alert box in C# code behind(显示“是/否后面的 C# 代码中的警告框)
问题描述
我正在尝试从 C# 中的代码隐藏显示是/否"消息框.如果用户单击是",我想调用AddRecord"过程,如果用户单击否",则什么都不做.
I am trying to display a "Yes / No" messagebox from codebehind in C#. I want to call an "AddRecord" procedure if the user clicks "Yes", and do nothing if the user clicks "No".
理想情况下,我想使用下面的代码,但来自代码隐藏:
Ideally, I want to use the code below, but from codebehind:
OnClientClick = "return confirm('Are you sure you want to delete?');"
我在 SO 和 google 上搜索,但找不到任何有用的东西.
I search on SO and google, but was not able to find anything helpful.
推荐答案
在您的添加记录"按钮上,只需执行以下操作:
on your Add Record button, just do the following:
<asp:button ID="AddRecordbutton" runat="server" Text="Add Record"
onclick="AddRecordButton_Click" onclientclick="return confirm('add record?');" />
在后面的代码中,只需将添加记录代码放在您的 AddRecordButton_Click 事件处理程序中.只有当他们在弹出窗口中单击是"时才会调用它.
In your code behind, just put the add record code in your AddRecordButton_Click event handler. It will only be called if they click Yes on the popup.
或者,您可以让代码隐藏在按钮最初呈现时分配 onclientclick 代码.
Alternatively, you could have your codebehind assign the onclientclick code when the button is initially rendered.
例如:
protected void Page_Load(object sender, EventArgs e) {
AddRecordButton.OnClientClick = @"return confirm('Add Record?');";
}
这篇关于显示“是/否"后面的 C# 代码中的警告框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:显示“是/否"后面的 C# 代码中的警告框


- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 输入按键事件处理程序 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01