[英]call JavaScript function from code behind
我在 ASPX 頁面中有這段 JavaScript 代碼
<script>
function show_modal(statut)
{
if (statut == true)
{
$(function ()
{
$('#modal_success').modal('show')
})
}
else
{
$(function ()
{
$('#modal_fail').modal('show')
})
}
}
</script>
這顯示了一個模態彈出窗口,我喜歡從后面的代碼中啟動它。
我試過這個,但沒有用:
if (resultat)
{
ClientScript.RegisterStartupScript(this.GetType(), "", "show_modal(true);");
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "", "show_modal(false);");
}
但我不知道為什么!
此調用要求您將調用包裝在<script>
標記中(或使用其他允許您指定是否添加腳本標記的重載)
ClientScript.RegisterStartupScript(this.GetType(), "",
"<script>show_modal(true);</script>");
要么
ClientScript.RegisterStartupScript(this.GetType(), "",
"show_modal(true);", true);
嘗試:
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), Guid.NewGuid().ToString(), script, true);
嘗試使用ScriptManager.RegisterClientScriptBlock 方法=> 它應該可以工作,更多信息請檢查錯誤控制台以跟蹤您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.