[英]ASP.Net Confirm box issue
在我的asp.net應用程序中,我使用了JavaScript確認框進行用戶確認。 這是代碼:
編輯:
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" OnClientClick="return confirm('Are you sure you want to proceed with the delete?');"/>
僅當用戶單擊“ OK
”時,才調用此工作爐排Button1_Click
。 但是我有更復雜的邏輯,會改變用戶的重放。 這是它的代碼:
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();
}
但是我無法得到用戶的回應。 如何捕捉用戶的回應? 可以幫忙嗎?
通過使用javascript確認方法,您可以只決定是否要繼續-因此可以確定只有在用戶單擊ok時才調用Button1_Click
方法。
您嘗試做的是完全不同的。 我建議擺脫ASP.NET Button控件,並使用“通用” HTML鏈接,例如:
<a href="#" id="decideLink">Click me</a>
然后在javascript中
document.getElementById('decideLink').onclick = function()
{
if(proceed) {
// do something here
} else {
// do something different
}
}
要從javascript調用代碼隱藏方法,請查看這篇關於從javascript調用網絡方法的文章
簡單的解決方案使用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.