ASP.Net确认框问题 [英] ASP.Net Confirm box issue
问题描述
在我的asp.net应用程序我已经使用的JavaScript确认框,用户确认。
这里是code:
In my asp.net application I have used JavaScript confirm box for user confirmation. Here is the code:
编辑:
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" OnClientClick="return confirm('Are you sure you want to proceed with the delete?');"/>
这是工作篦的button1_Click
只调用时用户点击确定
。但我有更复杂的逻辑,对用户重放变化。这里是code吧:
This is working grate Button1_Click
is only called when user clicks OK
. But I have more complex logic which changes on users replay. Here is the code for it:
protected void Button1_Click(object sender, EventArgs e)
{
// I want to catch replay of this confirm box
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Termination Failed", "confirm('This Contract Have a Pre-Renewed,Please Delete that Contract First')",true);
//If User Clicks ok
doWork();
//else
doWork2();
}
但我无法得到用户响应。我如何能赶上用户的响应?任何一个可以帮助?
But I am unable to get user response. How can I catch user response? Can any one help?
推荐答案
通过使用JavaScript的confirm方法,你只能决定,是否要继续或不 - 因此它是好的,你的的button1_Click
当用户点击的确定的
By using javascript confirm method you only decide, whether you want to continue or not - so it is ok that your Button1_Click
method is called only when user clicks ok.
你所要做的是完全不同的。我建议摆脱ASP.NET按钮控件,并使用类似共同的HTML链接:
What you trying to do is quite different. I would suggest to get rid of ASP.NET Button control and use "common" HTML link like:
<a href="#" id="decideLink">Click me</a>
然后在JavaScript
And then in javascript
document.getElementById('decideLink').onclick = function()
{
if(proceed) {
// do something here
} else {
// do something different
}
}
要调用code-从背后JavaScript方法,检查本的一篇关于从JavaScript调用Web方法
To call code-behind method from javascript, check this article about calling web methods from javascript
这篇关于ASP.Net确认框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!