如何防止母版页仅发布和发布内容页面 [英] how to prevent master page to be post and post only content page

查看:90
本文介绍了如何防止母版页仅发布和发布内容页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,



我是ASP.net的新手。

在我的母版页中,我设计了左菜单,

当我点击其中一个菜单然后向下滑动以显示其子菜单。

点击其子菜单后各个页面将被加载到ContentPlaceHolder,但是主页面的菜单将不会激活。



我应该怎么做才能在ContentPlaceHolder中加载另一个网页,同时主页的点击(选中)菜单项应该是活动的?



请帮帮我。



谢谢。

Dear sir,

I am new in ASP.net.
In my master page I have designed left menu,
when I clicked one of menu then it slide down to show its sub menu.
after clicking on its sub menu respective page will be loaded into "ContentPlaceHolder", but master page's menu will not be active.

What should i do for loading another webpage in ContentPlaceHolder and simultaneously master page's clicked(selected) menu item should be active?

Please help me.

Thank you.

推荐答案

母版页不是像iFrame那样的包装器。它是加载页面的模板。通过这种逻辑,您无法在不加载整个页面的情况下将内容加载到内容占位符中。



您可以确保在page_load上以各种方式保持选择菜单项或者你可以用其他方式加载不同的内容。



查看状态持久性,以便在页面更改时保持控件中的项目选择:高效的服务器端视图状态持久性 [ ^ ]。



此外,更新面板可用于执行部分回发。它实际上发布了整个页面,但只返回更新面板的ajax表示,然后将其加载到客户端的更新面板中: Ajax更新面板 - 最佳实践1 [ ^ ]。这对于即时更新的表单很方便,但你不应该将整个网站建立在它们上面。



我希望有所帮助。如果您需要任何特定实施方面的任何进一步指导,请告诉我,但在大多数情况下,发布新问题更好



祝你好运^ _ ^



Andy
Master page is not a wrapper like an iFrame is. It is a template for the page that loads. By this logic you cannot load the content "into" the content place holder without loading the whole page.

You can ensure that menu items remain selected in various ways on page_load or you can load different content in other ways.

Look into view state persistence to keep items selected in a control when the page changes: Efficient Server-Side View State Persistence[^].

Also, Update panels can be use to perform "partial" postbacks. it actually posts the whole page but only returns an ajax representation of the update panel which is then loaded into the update panel at the client side: Ajax update panel- best practice 1[^]. This is handy for forms that update on-the-fly but you shouldn't base a whole website on them.

I hope that helps. Please let me know if you need any further guidance on any particular implementation, but in most cases, posting a new question is better

Good luck ^_^

Andy


要完成Andy的回答,您还有其他选择:

- 如果您使用的是MVC ,你也可以使用AjaxHelper和部分视图。

HTTPS:// MSDN .microsoft.com / EN-US /库/ system.web.mvc.ajax.ajaxextensions.beginform(v = vs.118)的.aspx#L:system.Web.Mvc.Ajax.AjaxExtensions.BeginForm(System.Web程序。 Mvc.AjaxHelper,System.Web.Mvc.Ajax.AjaxOptions) [ ^ ]

- 转向单页应用程序设计。最简单的方法是利用淘汰赛 http://learn.knockoutjs.com/ [ ^ ]



- 最简单的方法就是使用iframe(虽然我不喜欢这个解决方案,但我已经看到它在许多地方使用过,特别是旧网站!)
To complete Andy's answer, you have some other choices:
- if you are using MVC, you could also use AjaxHelper combined with partial views.
https://msdn.microsoft.com/en-us/library/system.web.mvc.ajax.ajaxextensions.beginform(v=vs.118).aspx#M:System.Web.Mvc.Ajax.AjaxExtensions.BeginForm(System.Web.Mvc.AjaxHelper,System.Web.Mvc.Ajax.AjaxOptions)[^]
- going toward single page application design.one of the easiest way would be to utilize knockout http://learn.knockoutjs.com/[^]

- and the easiest way is to just use iframe (although I am not fan of this solution, I have seen it used in many places, specially older websites)!


这篇关于如何防止母版页仅发布和发布内容页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆