簡體   English   中英

javascript在asp.net Web應用程序中確認框重定向?

[英]Javascript Confirm box redirection in asp.net web application?

這是我的代碼

 Type cstype = this.GetType();
            ClientScriptManager cs = this.ClientScript;
            if (!cs.IsStartupScriptRegistered(cstype, "Script"))
            {
               String csScriptText = "confirm('Are you sure you want to leave the page');document.location='Default.aspx'";
                cs.RegisterStartupScript(cstype, "TestScript", csScriptText, true);

            }

我正在嘗試在我的Web應用程序中實現確認框,當用戶點擊退出按鈕時出現該確認框...使用ok選項並使用上述代碼取消。使用上述代碼,當用戶點擊“確認”上的“確定”。當用戶單擊“確認”上的“取消”按鈕時,我希望保留在同一頁面上。我該怎么做?

確認函數返回一個boolean值,指示用戶是選擇OK還是Cancel 因此,您需要做的就是在此函數返回true時重定向

String csScriptText = "if (confirm('Are you sure you want to leave the page')){document.location='Default.aspx';}";

只需向重定向添加條件。

Type cstype = this.GetType();
            ClientScriptManager cs = this.ClientScript;
            if (!cs.IsStartupScriptRegistered(cstype, "Script"))
            {
               String csScriptText = "if(confirm('Are you sure you want to leave the page')) {document.location='Default.aspx'}";
                cs.RegisterStartupScript(cstype, "TestScript", csScriptText, true);

            }
if (confirm('some text here')) {
    window.location = "Default.aspx";
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM