在页面之间导航时停止主页刷新?

时间:2021-10-01 19:57:49

I'm using Master Page in my ASP.net application, in the master page I put a ContentPlaceHolder in Update Panel to support AJAX in child pages, the question is how to stop Refreshing "master page controls" while navigating between pages?

我在ASP.net应用程序中使用母版,在母版中我在更新面板中添加了一个ContentPlaceHolder来支持子页面中的AJAX,问题是如何在页面之间导航时停止刷新“母版页控件”?

For navigation between pages I tried to use Response.Redirect, windows.location java script with no success, shall I use the Frames or IFrames instead of Master Pages to stop Refreshing?

为了在页面之间导航,我尝试使用响应。重定向,窗户。位置java脚本没有成功,我是否应该使用框架或iframe而不是母版页来停止刷新?

any suggestion to solve this issue will be highly appreciated, Thanks in advance...

如有任何解决此问题的建议,我们将不胜感激。

3 个解决方案

#1


5  

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.

如果您不想在切换“页面”时刷新页面,那么使用master page将不会有任何好的解决方案。正如其他人用不同的语言说的那样,母版页只是一个普通的“模板”,被不同的页面使用。导航就像调用不同的页面一样,当然会重新加载整个页面,包括主页面内容。

  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.

    我在使用Ajax时使用的一种汇总方法是,将每个“页面”作为用户控件,并将它们全部放在一个UpdatePanel中,并使用visible="false"。然后,对于“页面”之间的导航,切换用户控件的可见性,以显示正确的“页面”控件。

  2. The alternative is to use iframe.

    另一种选择是使用iframe。

Neither of these solutions use MasterPage.

这些解决方案都不使用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.

这个MasterPage概念是为了简化Ajax在ASP.NET中引入之前的常见外观而设计的。在Ajax流行之后,不刷新整个页面的需求变得更加普遍。

#2


2  

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.

母版只是扩展“普通”页面(大多数时候)应用程序的默认布局。主页面和contentplaceholder被呈现为一个完整的html页面。当您在页面之间导航时,整个页面刷新的行为是正常的。这就是网络的工作原理。

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

使用iframe可以解决您的问题。然而,这也有其他的副作用:

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

    整个主页已经不再有用了。iframe的内容是“母版”。

  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

    使用masterpage可以浏览到另一个url,也可以在浏览器的url栏中看到。当您使用iframe时,您将在iframe中导航到另一个页面。浏览器中的url将保持不变。当应用程序的用户点击refresh按钮时,它总是在html中为iframe分配的默认页面上重新启动。当然也有一些解决办法

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

无论如何。这取决于你的应用。围绕刷新行为有多种解决方案。

#3


1  

Having a structure like the one you've explained:

有一个你解释过的结构:

  • Master
    • Child page 1
    • 子页面1
    • Child page 2
    • 子页面2
    • ...
  • 主子页面1子页面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.

那么,当您从第1页切换到第2页时,您无法阻止页面刷新,因为在呈现给浏览器时,您只有一个“页面”实体(主内容+选定的页面内容)。

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.

如果您想在同一页面内的不同应用程序视图之间切换(为了防止整个页面刷新),您可以使用一个带有updatePanel的页面(Master变得非常无用),在其中加载不同的视图。

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.

您也可以使用iframe,但是如果您必须处理页面不同部分之间的任何类型的通信(其中一些在iframe中),我个人建议不要使用它们。

#1


5  

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.

如果您不想在切换“页面”时刷新页面,那么使用master page将不会有任何好的解决方案。正如其他人用不同的语言说的那样,母版页只是一个普通的“模板”,被不同的页面使用。导航就像调用不同的页面一样,当然会重新加载整个页面,包括主页面内容。

  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.

    我在使用Ajax时使用的一种汇总方法是,将每个“页面”作为用户控件,并将它们全部放在一个UpdatePanel中,并使用visible="false"。然后,对于“页面”之间的导航,切换用户控件的可见性,以显示正确的“页面”控件。

  2. The alternative is to use iframe.

    另一种选择是使用iframe。

Neither of these solutions use MasterPage.

这些解决方案都不使用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.

这个MasterPage概念是为了简化Ajax在ASP.NET中引入之前的常见外观而设计的。在Ajax流行之后,不刷新整个页面的需求变得更加普遍。

#2


2  

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.

母版只是扩展“普通”页面(大多数时候)应用程序的默认布局。主页面和contentplaceholder被呈现为一个完整的html页面。当您在页面之间导航时,整个页面刷新的行为是正常的。这就是网络的工作原理。

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

使用iframe可以解决您的问题。然而,这也有其他的副作用:

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

    整个主页已经不再有用了。iframe的内容是“母版”。

  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

    使用masterpage可以浏览到另一个url,也可以在浏览器的url栏中看到。当您使用iframe时,您将在iframe中导航到另一个页面。浏览器中的url将保持不变。当应用程序的用户点击refresh按钮时,它总是在html中为iframe分配的默认页面上重新启动。当然也有一些解决办法

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

无论如何。这取决于你的应用。围绕刷新行为有多种解决方案。

#3


1  

Having a structure like the one you've explained:

有一个你解释过的结构:

  • Master
    • Child page 1
    • 子页面1
    • Child page 2
    • 子页面2
    • ...
  • 主子页面1子页面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.

那么,当您从第1页切换到第2页时,您无法阻止页面刷新,因为在呈现给浏览器时,您只有一个“页面”实体(主内容+选定的页面内容)。

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.

如果您想在同一页面内的不同应用程序视图之间切换(为了防止整个页面刷新),您可以使用一个带有updatePanel的页面(Master变得非常无用),在其中加载不同的视图。

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.

您也可以使用iframe,但是如果您必须处理页面不同部分之间的任何类型的通信(其中一些在iframe中),我个人建议不要使用它们。