簡體   English   中英

如何在asp.net c#中執行下一行之前顯示警報彈出窗口

[英]How to display alert popup before execute next line in asp.net c#

我想在我的Web應用程序中顯示警報/消息。 我嘗試了以下代碼,但是在執行完所有代碼行后顯示警報。

ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Only alert Message');", true); 

但是我想在代碼執行的中間顯示我,是否有可能請幫助我。

正如我已經評論過的:

你不能。 您可以閱讀的RegisterStartupScript將注冊一個啟動腳本而不調用它。 此外,僅當客戶端接收到響應並進行處理時,才會調用此腳本。 您可以針對您的方案嘗試解決方法。 創建一個隱藏的按鈕,並定義警報該按鈕后要處理的功能。 然后在腳本中顯示警報,然后單擊此按鈕。

您的函數可能如下所示:

public string myFunction(){
  int a = 123;
  .
  .
  .

  ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Only alert Message');", true); 

  .
  .
  .
  .
  .
  return str;

}

您必須將此功能分為兩部分:

public string myFunction1(){
  int a = 123;
  .
  .
  .

  ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Only alert Message');", true); 

  return str;
}

public string myFunction2(){
  .
  .
  .
  .
  .

}

並將myFunction1與原始事件關聯,並將myFunction2與隱藏按鈕關聯。 然后將您的腳本更新為:

ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Only alert Message'); document.getElementById('<% hiddenBtn.clientId %>').click()", true); 

這將調用剩余的代碼和過程邏輯。

注意 這是一種解決方法 理想情況下,您應該嘗試拆分功能並嘗試使用后台處理。

暫無
暫無

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

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