且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

asp.net 在使用母版页的子页面cs后台代码中控制母版页中的登录控件显示

更新时间:2022-06-21 17:15:32

假设母版页中有这样一段html脚本

<div class="theme-popover" id="login_window" runat="server">
        <div class="theme-poptit">
            <a href="javascript:;" title="关闭" class="close">×</a>
            <h3>
                登录</h3>
        </div>
        <div class="theme-popbod dform">
            <div class="theme-signin">
                <ol>
                    <li>
                        <h4>
                            你必须先登录!如果您还不是本站会员请点击<a href="register.aspx" style="color:Red">注册</a></h4>
                    </li>
                    <li><strong>用户名:</strong><input id="login_user" runat="server" class="ipt" type="text"
                        name="log" value="" size="20" /></li>
                    <li><strong>密 码:</strong><input id="login_pwd" runat="server" class="ipt" type="password"
                        name="pwd" value="" size="20" /><a href="findpwd.aspx" style="margin-left: 10px;">忘记密码?</a></li>
                    <li>
                        <asp:Button ID="btnlogin" class="btn btn-primary" runat="server" OnClick="btnlogin_Click"
                            Text="登 录" /></li>
                </ol>
            </div>
        </div>
    </div>

在使用母版页的子页面中前台增加如下一个函数:

function showLoginDiv() {
           
$("div[id$='login_window']").show("fast");
        }

 

 

在使用母版页的子页面中后台cs中的按钮事件中调用前台的js函数即可

if (Session["USERNAME"].ToString() == "")
{
            ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>alert(\'请先登录!\');setTimeout(function(){showLoginDiv();},1000);  </script>");

}

else
{

    //登录用户的其他操作

}