代码隐藏的Bootstrap模式不工作

时间:2015-10-02 18:14:11

标签: javascript jquery asp.net twitter-bootstrap

当密码或用户不正确时需要打开模态它将保留在 Else ..但是,不起作用,它不起作用不打开模态

protected void bntLogar_Click(object sender, EventArgs e)
    {
        Registrar criptografia = new Registrar();

        if (Login.logarUsuario(txtUser.Text, criptografia.CriptografiaMD5(txtSenha.Text)))
        {
            //Cria um cookie do lado do servidor
            HttpCookie cookie = new HttpCookie("estado", "conectado");

            //Define a validade do cookie (10 dias a partir de hoje)
            cookie.Expires = DateTime.Now.AddMonths(12);

            //Envia o cookie para o cliente
            Response.Cookies.Set(cookie);

            //Redireciona para a pagina inicial
            Response.Redirect("Admin.aspx");

            //fortawsome
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Pop", "openModal();", true);
        }

    }

我将 JavaScript代码

放入其中
        <script type="text/javascript">
        function openModal() {
            $('#modalLogin').modal('show');
        }
    </script>

模态

<div class="modal fade" id="modalLogin" runat="server" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4>Warning</h4>
                </div>
                <div class="modal-body">
                    <p>Watch out! Your about to be locked out.</p>
                </div>
                <div class="modal-footer">
                    <a class="btn btn-primary" data-dismiss="modal">Close</a>
                </div>
            </div>
        </div>
    </div>

此网站站长中的<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "alert('Informations invalides');", true);

而不是

 ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Pop", "openModal();", true);

但我不知道它是否能解决你的问题。