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

发布于 2024-08-29 11:30:56 字数 263 浏览 4 评论 0原文

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

对于页面之间的导航,我尝试使用 Response.Redirectwindows.location java 脚本但没有成功,我应该使用 Frames 或 IFrames 而不是母版页来停止刷新吗?

任何解决此问题的建议将不胜感激,提前致谢...

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?

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?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

仅此而已 2024-09-05 11:30:56

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

  1. 我使用 Ajax 的解决方案是
    将每个“页面”作为用户
    控件,并将它们全部放在一个
    UpdatePanel 带有 visible="false"
    然后要在“页面”之间导航,请切换
    用户控件的可见性
    显示正确的“页面”控件。

  2. 替代方法是使用 iframe。

这些解决方案都不使用 MasterPage。

MasterPage 概念旨在简化 ASP.NET 中引入 Ajax 之前的常见外观。 Ajax流行之后,不刷新整个页面的需求就更加普遍了。

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.

我爱人 2024-09-05 11:30:56

母版页只不过是使用(大多数时候)应用程序的默认布局来扩展“正常”页面。母版页和内容占位符呈现为完整的 html 页面。当您在页面之间导航时,刷新整个页面是正常行为。这就是网络的运作方式。

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

  1. 整个母版页不再有用。 iframe 周围的内容是“母版页”。

  2. 使用母版页,您实际上会浏览到另一个网址,您还会在浏览器的网址栏中看到。当您使用 iframe 时,您可以在 iframe 内导航到另一个页面。浏览器中的 URL 将保持不变。当应用程序的用户点击刷新按钮时,它总是会在您在 html 中分配给 iframe 的默认页面重新启动。当然,有一些解决方法

。这实际上取决于您的应用程序。有多种解决方案可以解决刷新行为。

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.

时光礼记 2024-09-05 11:30:56

具有类似于您所解释的结构:

  • Master
    • 子页面 1
    • 子页面 2
    • ...

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

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文