[英]ASP.Net Confirm box issue
In my asp.net application I have used JavaScript confirm box for user confirmation. 在我的asp.net应用程序中,我使用了JavaScript确认框进行用户确认。 Here is the code: 这是代码:
EDIT : 编辑:
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" OnClientClick="return confirm('Are you sure you want to proceed with the delete?');"/>
This is working grate Button1_Click
is only called when user clicks OK
. 仅当用户单击“ OK
”时,才调用此工作炉排Button1_Click
。 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? 可以帮忙吗?
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 . 通过使用javascript确认方法,您可以只决定是否要继续-因此可以确定只有在用户单击ok时才调用Button1_Click
方法。
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: 我建议摆脱ASP.NET Button控件,并使用“通用” HTML链接,例如:
<a href="#" id="decideLink">Click me</a>
And then in javascript 然后在javascript中
document.getElementById('decideLink').onclick = function()
{
if(proceed) {
// do something here
} else {
// do something different
}
}
To call code-behind method from javascript, check this article about calling web methods from javascript 要从javascript调用代码隐藏方法,请查看这篇关于从javascript调用网络方法的文章
Simple solution use javascript and call OnClientClick
简单的解决方案使用javascript并调用OnClientClick
<script type="text/javascript">
function confirm() {
if (confirm('This Contract Have a Pre-Renewed,Please Delete that Contract First')) {
return true;
}
else {
return false;
}
}
</script>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" OnClientClick="return
confirm()"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.