我有这个问题..我有一个“登录”链接按钮和一个"UserList“链接按钮在一个母版页。当用户登录并单击" UserList“链接按钮时,具有上面提到的母版页的UserList页面将打开。(我已经实现了这一点)。
但是如果用户没有登录,而他点击了"UserList",那么应该调用“登录”链接按钮的点击。我如何才能做到这一点?请帮帮我..
发布于 2009-07-07 17:31:08
试试这个:
在MasterPage的HTML中:
为LinkButtonLogin's onclick事件定义事件处理程序:
<asp:linkbutton id="LinkButtonLogin" runat="server"
text="Login" onclick="LinkButtonLogin_Click"></asp:linkbutton>创建一个从视图中隐藏的虚拟按钮。然后,对于ModalPopupExtender,,将ModalPopupExtender控件的TargetControlID从LinkButtonLogin更改为ButtonInvisible.这有效地将ModalPopupExtender伪装成可隐藏/可显示的代码。
<asp:button id="ButtonInvisible" runat="server" style="display: none;" />在MasterPage的代码背后
protected void Page_Load(object sender, EventArgs e)
{
/*
This adds a client-side event to your HyperLink control that mimics
LinkButtonLogin's onclick event, but ONLY if the current user is not
logged in.
*/
if (!UserIsLoggedIn())
{
HyperLinkUserList.Attributes.Add("onclick",
"document.getElementById('" +
LinkButtonLogin.ClientID + "').click();");
}
}
protected void LinkButtonLogin_Click(object sender, EventArgs e)
{
// check if the user is logged in.
if (!UserIsLoggedIn())
{
// show the modal login window
ModalPopupExtender.Show();
}
else
{
/*
This assumes that you always want a user to
go to the UserList page upon being logged in.
You can add some code here to redirect to
different pages based on certain criteria.
*/
Response.Redirect("userlist.aspx");
}
}发布于 2009-07-07 17:40:10
一种方法是在web.config文件中添加一个授权部分,当用户单击UserList链接但用户未登录时,该部分将触发登录页面:
<location path="UserList.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>如果对您的应用程序有意义,您甚至可以使用<asp:LoginView>控件对未登录的用户隐藏用户列表链接。
https://stackoverflow.com/questions/1093610
复制相似问题