私のコードビハインドには検索機能があり、その最初と最後にJavaScriptを呼び出したいと思っています。
これを行うために、私はいくつかの方法を試しましたが、誰もうまくいきません!
ここで私が試したこと:
これ :
this.Page.ClientScript.RegisterStartupScript(this.GetType(), string.Empty, "<script type='text/javascript'>document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block';</script>");
これ :
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Wait", "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block';", true);
それにもかかわらず、私は .aspx に関数を書きました:
function wait() {
document.getElementById('light').style.display = document.getElementById('light').style.display == 'block' ? 'none' : 'block';
document.getElementById('fade').style.display = document.getElementById('fade').style.display == 'block' ? 'none' : 'block';
}
そして、次のように呼び出してみてください:
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Wait", "<script>wait();</script>");
この :
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Wait", "<script>wait();</script>");
私が間違っていることについて何か考えはありますか?
編集
ここで関数を呼び出します。1 つはif
実行中、もう 1 つelse
は実行中です。
if (someTest())
{
this.someControl.CssClass = "alert_Class";
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>noCriteriasEnter();</script>");
this.someControl.Focus();
return;
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Wait", "<script>wait();</script>");
}
編集2
最高が来ています:C#関数(コードビハインド)の最後で関数を呼び出すと、実行されます!!!