天天看點

asp.net 在使用母版頁的子頁面cs背景代碼中控制母版頁中的登入控件顯示

假設母版頁中有這樣一段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>

                        <asp:Button ID="btnlogin" class="btn btn-primary" runat="server" OnClick="btnlogin_Click"

                            Text="登 錄" /></li>

                </ol>

            </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

    //登入使用者的其他操作

繼續閱讀