[英]Display confirmation messagebox c# in ASP.NET
我在研究時發現了這些代碼,但它們並不是我真正想要的:
第一種解決方案:
private void MsgBoxConfirmDelete(string sMessage)
{
string msg = "<script language=\"javascript\">";
msg += "var conf = confirm('Are you sure you want to delete this image?');";
msg += " if(conf == true){ (alert(....));}";
msg += "</script>";
Response.Write(msg);
}
第二解決方案:
protected void Button1_Click(object sender, EventArgs e)
{
ClientScriptManager CSM = Page.ClientScript;
if (!ReturnValue())
{
string strconfirm = "<script>if(!window.confirm('Are you sure?')){window.location.href='Default.aspx'}</script>";
CSM.RegisterClientScriptBlock(this.GetType(), "Confirm", strconfirm, false);
}
}
bool ReturnValue()
{
return false;
}
我發現的大多數解決方案都是“ onclientclick / onclick”,但是我需要的是在運行我的方法(有點像是“在……之間”)時顯示一條確認消息。 因此,我非常需要IF / ELSE。 任何人都知道如何從這樣的確認消息中檢索結果嗎?
例如:
消息:讀取時發現一些重復數據,確定要繼續嗎? 提示:是/否
對異步請求處理進行一些研究。 客戶端Web代碼將需要回撥給服務器,以檢索數據處理過程中的更新“狀態”。 服務器代碼可以發送回一般狀態(即,完成200條記錄中的15條),或者可以發送回信號以提示使用進行確認。
使用ModalPopupExtender(ajax控件)。 開按鈕單擊顯示彈出窗口。 在“控件”中,為您的容器提供targetControlID,其中包含要顯示的消息以及兩個相應的按鈕以進行確認。
我在網上找到了本教程,並且看來行為正確:
if (MessageBox.Show("Are you sure you want to delete this list and it's related jobs? There is no going back!","Confirm delete", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
// a 'DialogResult.Yes' value was returned from the MessageBox
// proceed with your deletion
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.