2011-02-01 11 views
0

私のaspxページにボタンがあります。私はそのボタンをクリックして実行を続行する前にjavascriptの確認を使用したい。私はaspxページ自体にjavascriptを書いているなら、簡単にそれを行うことができます。しかし、私の問題は、確認メッセージが異なる可能性があるたびにです。適切な確認メッセージを生成するために、さまざまな条件を確認する必要があります。JavaScriptをC#のコードの背後にあるコードで確認します。

私のコードの中でconfirmをコールすることができますので、そこから確認メッセージを作成できますか?

私は何をしようとしていることである:

protected void Button1_Click(object sender, EventArgs e) 
{ 
     //just the algorithm given here 
     string message=constructMessage(); \\ its just a function to construct the confirm message 
     if(confirm(message)) // i know i cant use javascript in code behind direct. How can i do this 
      { 
      //do something 
      } 
      else 
      { 
      // do nothing 
      } 
} 
+0

が完了しました。お返事ありがとうございました。 –

+0

[call js confirm from code behind]の複製が可能です。(http://stackoverflow.com/questions/1491210/call-js-confirm-from-code-behind) –

答えて

2
protected void Button1_Click(object sender, EventArgs e) 
{ 
      string message= 
      "if(confirm("+message+")) 
       { 
        //do something 
       } 
       else 
       { 
       // do nothing 
      }"; 
      this.ClientScriptManager.RegisterStartupScript(typeof(this.Page), "warning",   message, true); 
       //Prints out your client script with <script> tags 

    }  

さらに参照するためにClientScriptManager

+0

@Null Pointer:何かがあなたの解決策を見つけるのを助けた場合、あなたは答えをマークすることができます。 –

関連する問題