日期:2014-05-19  浏览次数:20469 次

如何在asp.net中弹出一个提示框,当单击“是” 执行一个操作,当单击“否”执行另一个操作
如何在asp.net中弹出一个提示框,当单击“是”   执行一个操作,当单击“否”执行另一个操作   ?

------解决方案--------------------
将js的confirm函数指给一个可以回传的服务器控件,比如一个按钮或者链接,这样就可以控制后台过程是否执行了。
------解决方案--------------------
试试
//aspx
<form id= "Form1 " method= "post " runat= "server ">
<asp:button id= "Button1 " runat= "server " Text= "Button "> </asp:button>
</form>

//aspx.cs
public class Test : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
Button1.Attributes.Add( "onclick ", "return confirm( '确定? '); ");
}

private void Button1_Click(object sender, System.EventArgs e)
{
Button1.Text = "abc ";
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}


------解决方案--------------------
比较上路的控件开发者应该使用 IPostbackEventHandler 接口来触发后台捕获“是/否”结果。不过,我们这里用个变通的办法,用个 HiddenField,这样初学者可以少学点技术,但是可以达到同样的功能。

并且你也没有说明这个弹出的提示框是在什么交互逻辑下被弹出的。我假设你是在按钮Button1按下之后弹出这个选择。

首先,在设计器上拖入一个HiddenField控件,假设命名其ID为 YesOrNo。

然后,在代码中写:

Button1.OnClientClick=YesOrNo.ClientID+ ".value=confirm( '确定? '); ";

最后,在 YesOrNo 控件的 ValueChanged 事件中根据它的 Text 值(true 和 false 字符串)处理结果。

注意,应该注册 Button1的 Click 事件,但是可以空着什么都不做(但一定要注册事件)。
------解决方案--------------------
噢,终于明白楼主的意思了.
如果是我的话,我就为一个隐藏的TextBox赋值,if (Confirm( '是/否 ')==true){document.getElementByID( 'Hid ').value= 'Y '}else{document.getElementByID( 'Hid ').value= 'N '}
然后在ButtonClick里事件判断一下Hid.text就可以了.

If Hid.text= "Y " then
....
else
...
end if