0

我在 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);");
        }

但我不知道为什么!

4

3 回答 3

4

此调用要求您将调用包装在<script>标签中(或使用允许您指定是否添加脚本标签的其他重载)

ClientScript.RegisterStartupScript(this.GetType(), "", 
                "<script>show_modal(true);</script>");

或者

ClientScript.RegisterStartupScript(this.GetType(), "", 
                "show_modal(true);", true);
于 2012-12-07T12:30:48.133 回答
1

尝试:

ScriptManager.RegisterStartupScript(this.Page, typeof(Page), Guid.NewGuid().ToString(), script, true);
于 2012-12-07T12:29:57.557 回答
0

尝试使用ScriptManager.RegisterClientScriptBlock Method => 它应该可以工作,更多信息请检查错误控制台以跟踪您的问题。

于 2012-12-19T05:27:58.290 回答