Stop Master page refreshing while navigating between pages?

a 夏天 提交于 2019-12-05 05:07:14

If you don't want the page to refresh when switching between "pages", you will not have any good solution using master page. As others have said in different words, the master page is just a common "template" that is used by different pages. The navigation between is just like calling different pages, and of course will reload the entire page, including the master page content.

  1. A sollution I have used with Ajax is to have each "page" as a user controls, and put them all in an UpdatePanel with visible="false". Then for navigation between "pages", switch visibility for the user controls to show the right "page" control.

  2. The alternative is to use iframe.

Neither of these solutions use MasterPage.

The MasterPage concept was designed to simplify a common look before Ajax was introduced in ASP.NET. After Ajax became popular, the demand for not refreshing the entire page has been more common.

A masterpage is nothing more than extending your "normal" page with (most of the time) the default layout of your application. The master page and the contentplaceholders are rendered as a full html page. When you navigate between pages it is the normal behavior that your whole page refreshes. This is how the web works.

Working with an iframe could solve your problem. However that has some other side effects:

  1. The whole masterpage isn't useful anymore. The content around your iframe is the "masterpage".

  2. With a masterpage you actually browse to another url, you also see in the url bar of your browser. When you work with an iframe you navigate within the iframe to another page. The url in your browser will stay the same. When the user of your application hits the refresh button it always starts again at the default page you assigned to your iframe in the html. Of course there are some workarounds

Anyway. It really depends on your application. There are multiple solutions to work around the refresh behavior.

Having a structure like the one you've explained:

  • Master
    • Child page 1
    • Child page 2
    • ...

Then you cannot prevent the page from refreshing when you switch from page 1 to page 2 etc. for you have a single "page" entity (master content + selected page content) when it's rendered to the browser.

If you want to switch betweent different app views inside the very same page (so to prevent a complete page refresh) you could use a single page (the Master becomes quite useless) with an updatePanel in which you load the different views.

You can also use iFrames, but if you have to handle any type of communication between different parts of the page (some of which are inside iFrames) I would personally advice not to use them.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!