在验证失败时保持对话框打开

时间:2011-09-29 18:50:59

标签: c# jquery asp.net postback jquery-ui-dialog

尝试在没有Ajax的情况下实现这一目标。

的javascript

jQuery(function () {
        // Modal Login.
        jQuery(".ModalBoxLogin").dialog({
            autoOpen: false,
            bgiframe: true,
            height: 155,
            resizable: false,
            draggable: false,
            width: 353,
            modal: true,
            open: function (type, data) {
                // Hide Close
                jQuery(".ui-dialog-titlebar-close").hide();
                // include modal into form
                jQuery(this).parent().appendTo(jQuery("form:first"));
                //clear all text.
                jQuery(this).find(':text').val('');
                jQuery(this).find(':password').val('');
            },
            close: function () {
                //clear all text.
                jQuery(this).find(':text').val('');
                jQuery(this).find(':password').val('');
            }
        });
    });

HTML

    <%--Login Dialog--%>
    <asp:Panel ID="pnlLogin" runat="server" CssClass="ModalBoxLogin" title="LOGIN">
        <div class="ModalBox_conteudo">
            <div class="ModalBox_esq">
                <asp:Label ID="lblEmail" Text="E-MAIL:" runat="server" />
                <asp:Label ID="lblSenha" Text="SENHA:" runat="server" />
            </div>
            <div class="ModalBox_dir">
                <asp:TextBox ID="txtEmail" runat="server" placeholder="Digite o seu e-mail" />
                <br />
                <asp:TextBox ID="txtSenha" TextMode="Password" runat="server" placeholder="Digite a sua senha"/>
                <br />
                <asp:LinkButton ID="btnLogar" runat="server" CssClass="btnOk" OnClick="btnLogar_Click" />
                <br/>
                <asp:Label ID="lblMensagemLogin" runat="server"></asp:Label>
                <asp:Literal ID="litScriptLogin" runat="server"></asp:Literal>

            </div>
            <div class="ModalBox_links">
                <asp:HyperLink ID="hlCadastroLogin1" NavigateUrl="" Text="Ainda não tem cadastro?" runat="server" />
                <span>&nbsp;|&nbsp;</span>
                <asp:HyperLink ID="hlCadastroLogin2" NavigateUrl="" Text="Esqueceu a senha?" runat="server" />
            </div>
        </div>
    </asp:Panel>

CS

    protected void btnLogar_Click(object sender, EventArgs e)
    {
        ControllerCliente controllerCliente = new ControllerCliente();
        controllerCliente.Cliente.Email = txtEmail.Text;
        controllerCliente.Cliente.Senha = Util.Criptografar(txtSenha.Text);
        controllerCliente.Carregar();

        if (controllerCliente.Cliente.ClienteCodigo > 0)
        {
            hlLogin.Visible = false;
            hlCadastro.Visible = false;
            lblP.Text = "Olá " + controllerCliente.Cliente.Nome;

            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "dialog", "alert('oi');", true);

            //litScriptLogin.Text = "<script>alert('teste');</script>";

            //litScriptLogin.Text = "<script>getElementById('" + pnlLogin.ClientID + "').style.display='none';</script>";
            //pnlLogin.Style["display"] = "none";
        }
        else
            lblMensagemLogin.Text = "Email ou senha inválido.";
    }

如果我在本节中使用updatePanel:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:LinkButton ID="btnLogar" runat="server" CssClass="btnOk" OnClick="btnLogar_Click" />
                        <br/>
                        <asp:Label ID="lblMensagemLogin" runat="server"></asp:Label>
                        <asp:Literal ID="litScriptLogin" runat="server"></asp:Literal>
                    </ContentTemplate>
                </asp:UpdatePanel>

当我成功时,对话框不会关闭。

我想念的任何方式?

问候

编辑:只是添加一些东西......

javascript致电:

    /* Modal */
    jQuery(".ModalBoxOpenLogin").live("click", function myfunction() {
        jQuery(".ModalBoxLogin").dialog("open");
    });

    jQuery(".ModalBoxOpenCadastro").live("click", function myfunction() {
        jQuery(".ModalBoxCadastro").dialog("open");
    });

HTML电话:

<asp:UpdatePanel ID="UpdatePanel2" runat="server">
                            <ContentTemplate>
                                <asp:HyperLink ID="hlLogin" runat="server" Text="Log in" CssClass="menu_log_menu ModalBoxOpenLogin"></asp:HyperLink>
                                <asp:Label ID="lblP" runat="server" Text="|" style="margin-left:5px; cursor:default;color:#CCCCCC;" ></asp:Label>
                                <asp:HyperLink ID="hlCadastro" runat="server" Text="Cadastre-se" CssClass="menu_log_menu ModalBoxOpenCadastro"></asp:HyperLink>
                            </ContentTemplate>
                        </asp:UpdatePanel>

0 个答案:

没有答案