2017-03-22 5 views
-2

JavaScriptコード内の何かが起こった場合に備えて、javascript関数を呼びたいと思います。ボタンを押してASP.NETでJavaScriptを実行する

以下のコードのようなものであれば、ポストバック警告ウィンドウが表示され、正しく表示された後に正常に動作します。しかし、他のブロックからコメントを削除する場合は、elseブロック内の2つのスクリプトのどれもブロックされません。

コードビハインドからこれらの操作の回数を制限できますか?それが動作します

if (condition) { 
    if (condition2) { 
    var message = "It happened !"; 
    Page.ClientScript.RegisterStartupScript(this.GetType(), "yep1", "alert('" + message + "')", true); 
    } 

} else { 
    var msg = "It does not work like that"; 
    Page.ClientScript.RegisterStartupScript(this.GetType(), "nope1", "alert('" + msg + "!')", true); 
    //Page.ClientScript.RegisterStartupScript(this.GetType(), "nope2", "alert('" + msg + "')", true); 
} 

答えて

1

この方法です。関数の名前が言うように、あなたがそれを行うだろう。このようにして、2を挿入するのではなく、それを変更しているので、それは、起動スクリプトを登録し、両方^^

if (condition) 
 
{ 
 
    if (condition2) 
 
    { 
 
     var message = "It happened !"; 
 
     Page.ClientScript.RegisterStartupScript(this.GetType(), "yep1", "alert('"+message+"');", true); 
 
    } 
 
} 
 
else 
 
{ 
 
    var msg = "It does not work like that"; 
 
    Page.ClientScript.RegisterStartupScript(this.GetType(), "nope1", "alert('"+msg+"!'); alert('" + msg + "');", true); 
 
    //Page.ClientScript.RegisterStartupScript(this.GetType(), "nope1", "alert('"+msg+"!')", true); 
 
    //Page.ClientScript.RegisterStartupScript(this.GetType(), "nope2", "alert('" + msg + "')", true); 
 
}

+0

ので、起動スクリプトの数という1つ以上の関数を呼び出す方法は、それらを1つの文字列にチェーンすることですか? 2番目のif文ではただのメモmsgは宣言されていません。 //はいです。どうもありがとうございました。 – Bendom

関連する問題