DialogResult dr = MessageBox.Show("Aer you sure?", "show", MessageBoxButtons.OKCancel);
if (dr == DialogResult.OK)
{
)//判断是否是点击的确定(OK)
}
你是java,我认得
@blog_yuan: 不是啊
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (!this.IsClientScriptBlockRegistered("clientScript"))
{
// Form the script that is to be registered at client side.
String scriptString = "<script lanage='javascript'>if (confirm('Confirm me?')) __doPostBack('LinkButton1','')</script>";
this.RegisterClientScriptBlock("clientScript", scriptString);
}
//Page.ClientScript.RegisterStartupScript(this.GetType(), "Cscript", "<script> (function(){ if(!confirm('确认要切换为实时交易吗?')){ return false; } })() </script>");
show();
} 这样的可以使用,谢谢你的解答
点确定就return true;点取消就return false;
要点击取消之后,不再执行后面的C# 代码, Page.ClientScript.RegisterStartupScript(this.GetType(), "Cscript", "<script> confirm('确认要切换为实时交易吗?') </script>"); 执行之后点击取消不再执行show() 方法。
show();
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function go() { if (confirm("你好!")) { return true; } else { return false; } } </script> </head> <body> <form id="form1" runat="server" onsubmit="return go()"> <div> hello!<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </div> </form> </body> </html>
添加Confirm确认弹出窗体:
在page_load里面添加代码(以button为例子)
Button.Attributes.Add("onclick","return confirm(''确定?'')")
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (!this.IsClientScriptBlockRegistered("clientScript"))
{
// Form the script that is to be registered at client side.
String scriptString = "<script lanage='javascript'>if (confirm('Confirm me?')) __doPostBack('LinkButton1','')</script>";
this.RegisterClientScriptBlock("clientScript", scriptString);
}
//Page.ClientScript.RegisterStartupScript(this.GetType(), "Cscript", "<script> (function(){ if(!confirm('确认要切换为实时交易吗?')){ return false; } })() </script>");
show();
} 这样的可以使用,谢谢你的解答
在Button的OnClientClient事件中直接写 JavaScript:return confirm('确定提交吗?')如下
<asp:Button runat="server" id="bunID" OnClientClient='JavaScript:return confirm('确定提交吗?')' />
对于Asp.net的按钮来说,直接设置OnClientClick="return confirm('你确定要操作吗?')",类似这样的即可。
confirm提示框的应用就可以了