显示“是/否"后面的 C# 代码中的警告框

Display a quot;Yes / Noquot; alert box in C# code behind(显示“是/否后面的 C# 代码中的警告框)
本文介绍了显示“是/否"后面的 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# 代码中的警告框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)