您的位置:首页 > 编程语言 > ASP

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

2013-09-29 18:28 701 查看
假设母版页中有这样一段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
{
    //登录用户的其他操作
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: