如何使母版页仅继承另一个母版页的一项功能
我有 2 个母版页,分别称为 User.Master 和 Admin.Master。顾名思义,Admin.Master 是针对管理员的,User.Master 是针对用户的。 User.Master 具有登录和注销功能以及自己的侧边栏。 Admin.Master 有自己的侧边栏。现在我希望 Admin.Master 继承登录和注销功能,但不继承 User.Master 的侧边栏。我怎样才能做到这一点?
I have 2 masterpages called User.Master and Admin.Master. Admin.Master as the name suggests is for administrator and User.Master is for users. The User.Master has Login and Sign-Out functionality and a sidebar of its own. The Admin.Master has a sidebar of its own. Now I want the Admin.Master to inherit Login and Sign-Out functionality but not the User.Master's sidebar. How can I achieve that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建第三个母版页
LogInOut.master
,其中包含登录和注销内容,然后您可以从中派生User.master
和Admin.master< /code>,为每个提供其特定的侧边栏。
Create a third master page,
LogInOut.master
, which includes the login and logout stuff, and from which you then derive bothUser.master
andAdmin.master
, providing each with their specific sidebar.您需要 3 个母版页才能做到这一点。
1) 主要主控 - 登录和注销
2) 用户主控 - 继承主主控 |用户侧栏
3) 管理员大师 - 继承主大师 |管理侧栏
编辑:^^ 打败我!
You need 3 master pages to do that.
1) Primary Master - Login and Sign-out
2) User Master - Inherits Primary Master | User Side Bar
3) Admin Master - Inherits Primary Master | Admin Side Bar
Edit: ^^ Beat me!
有(至少)三种方法可以相当简单地做到这一点,其中我更喜欢第一种方法:
只需为登录/退出功能创建一个用户控件,并在两个母版页上包含相同的用户控件(用户/admin)。
完全跳过双母版页方法。相反,只有一个母版页,其中包含用于登录/注销功能的用户控件,以及每个用于侧边栏的用户控件。加载哪个用户控件(例如加载到母版页上的占位符中)是在母版页后面的代码中控制的,您可以在其中检查登录等的会话详细信息。
正如其他几个人所建议的那样,使用 3 个母版页,每个母版页嵌套其他。
There are (at least) three ways to do this fairly simply, of which I prefer the first approach:
Just create a user control for the log in/out functionality, and include the same user control on both master pages (user/admin).
Skip the double master pages approach completely. Instead have just one master page with a user control for the log in/out functionality, and a user control each for the side bars. Which user control is loaded (e.g. into a placeholder on the masterpage) is controlled in the master page's code behind, where you can check for session details on login etc.
As several others have suggested, use 3 master pages that nest each other.