显示A"是/否]在C#$ C $Ç背后警告框 [英] Display a "Yes / No" alert box in C# code behind

查看:198
本文介绍了显示A"是/否]在C#$ C $Ç背后警告框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示是/否从codebehind在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".

在理想情况下,我想用下面的code,但codebehind:

Ideally, I want to use the code below, but from codebehind:

OnClientClick = "return confirm('Are you sure you want to delete?');"

我搜索的SO和谷歌,但未能找到任何有帮助的。

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

在你的code后面,只需把添加记录code在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.

另外,你可以有你的codebehind分配按钮时,最初呈现的OnClientClick code。

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

这篇关于显示A&QUOT;是/否]在C#$ C $Ç背后警告框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆