针对asp页面的母版页内容过滤
我有一个带有标题和菜单的母版页,现在我想如果我打开login.aspx页面,母版页的菜单应该隐藏,其余标题将保留在那里,意味着母版页是必需的但没有菜单,什么是最好的解决这个问题?
I have a Master page having title and menu, now i want if i open login.aspx page, the menu of the master page should be hided, rest title will remain there, means master page is required but without menu, what is the best solution for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
获取菜单控件并将其 Visible 属性设置为 false
警告:这个好处是通过硬编码 ID 找到控制,因此可能会引发 NullReferenceException
Get the menu control and set its Visible property to false
Warning: this good is finding control with hard coded ID so it may trow NullReferenceException
您可以使用属性来显示或隐藏母版页中的菜单。
注意
:如果菜单是静态的,您可以将其包围在 PlaceHolder 控件中,并使用此控件管理显示/隐藏它。我选择这个特定的控件来进行建议,因为它不会呈现额外的 HTML,因此页面中没有任何变化。
。
然后在登录页面中,说“页面加载”或其他内容(不是在预初始化或这么早的时间,已经创建了母版页):
。
更新
解决此问题的另一种方法是使用嵌套母版页。子母版页包含菜单和其他内容,是所有页面的默认母版页。父母版页包含所有重要的内容,甚至适用于登录页面。
如果您已经有一个母版页,则可以创建另一个母版页,将大部分内容从现有母版页移至另一个母版页,对内容占位符使用相同的 ID,然后使现有母版页本身具有母版页文件集到新的,然后应该很容易进入登录页面并将母版页文件名更改为新的母版页文件。
You can have a property to show or hide menu in the master page.
like
Note: if the menu is static, you can surround it in PlaceHolder control and manage showing/hiding it using this control. I chose this specific control to suggest as it doesn't render extra HTML so, nothing changes in page.
.
Then in the login page, say Page Load or something (not in pre init or such early times, to have master page created already):
.
Update
Another way to solve this is to have nested master-pages. The child master page has the menu and other stuff and is the default master-page for all pages. The parent master-page has all the important stuff that applies even to the login page.
If you already have a master page, you can create another one, move most stuff to the other one from your existing master page, use the same IDs for content place holders, and then make the existing master-page itself have an masterpage file set to the new one, and then it should be easy to go to login page and also change the master-page file name to the new master-page file.
你可以像下面这样做。将其放在母版页的代码后面。
You can do like the following. Put this in master page's code behind.