我可以在 MasterPage 中使用 UpdatePanel 来包装嵌套页面吗?

发布于 2024-07-10 02:07:08 字数 166 浏览 7 评论 0原文

我可以使用母版页中的更新面板来包装嵌套页面,以便从一个页面浏览到另一个客户端时仅获得部分刷新(母版页不会重新加载)。

如果是这样 - 怎么办? 我是否只需在母版页中的 ContentPlaceholder 周围放置一个更新面板?

任何帮助表示赞赏!

Can I use Update panel in masterpage to wrap nested pages so that when browsing from one page to the other client only gets a partial refresh (MasterPage doesn't get reloaded).

If so - how? Do I Just put an update panel around the ContentPlaceholder in the Master Page?

Any help appreciated!

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

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

发布评论

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

评论(1

我不建议您将整个页面包含在 UpdatePanel 中,原因如下:

  • 如果您希望搜索引擎将您的网站编入索引,您将需要在单独的页面上显示您的内容...只需在每个内容部分上使用不同的查询字符串就足够了。 这是因为对于搜索引擎来说内容为王并且由于搜索引擎目前无法索引动态生成的数据,因此它们将无法索引您的网页。

  • 将整个页面包含在更新面板中是非常危险的,因为发送到服务器的开销巨大。 如果这样做,您会发现性能显着下降。 阅读这篇文章了解更多信息主题

  • 由于开销巨大,建议使用更新面板仅更新网站的一小部分(例如侧面的小框小部件,等...)而不是整个内容部分。

  • 将内容部分包含在更新面板中意味着您必须自己手动动态更改 url(使用 # 锚点),这样您就可以让用户能够使用其上的后退按钮浏览器转到网站的上一部分。 无法返回页面对于用户来说非常烦人


以下示例演示了 UpdatePanel 的问题。

以下是带有标签和按钮的简单 aspx 页面的代码

<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" ID="up1">
 <ContentTemplate>
   <asp:Label runat="server" ID="Label1" Text="Update Me!" /><br />
   <asp:Button runat="server" ID="Button1" 
     Text="Postback Update" OnClick="Button1_Click" />
 </ContentTemplate>
</asp:UpdatePanel>

protected void Button1_Click(object sender, EventArgs e)
{
  Label1.Text = DateTime.Now.ToLongDateString();
}

以下是单击按钮时使用 UpdatePanel 完成的部分回发(请注意涉及的巨大开销):

            替代文字
(来源:encosia.com

正如您所看到的,服务器基本上将 UpdatePanel 中的所有元素发送回客户端。


另一方面,这里是一个涉及使用 ASP.Net 页面方法。 请注意这次从服务器发送的响应(不涉及 UpdatePanel

:      替代文字
(来源:encosia.com

I do not advise you to wrap an entire page in an UpdatePanel, for the following reasons:

  • If you want your site to be index by Search Engines, you will need to display your content on separate pages...just having a different querystring on each content section is enough. This is because for search engines Content Is King and since search engines currently cannot index dynamically generated data, they will not be able to index your pages.

  • Wrapping entire pages in an Update Panel is very dangerous because of the huge overhead that is sent to the server. You will see a significant performance decrease if you do so. Read this article for more information on the subject

  • Because of this huge overhead, it is suggested to use the Update Panel to update just small sections of the website (like little box widgets on the side, etc...) and not whole content sections.

  • Wrapping content sections in an update panel means that you will have to go the extra mile dynamically changing the url (using # anchors) manually yourself, and this is so that you will give users the ability to use the back button on their browser to go to the previous section of the site. Not having the ability to go back in a page is very annoying for users


Here is an example that demonstrates the problem with UpdatePanels.

The following is code for a simple aspx page with a label and a button :

<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" ID="up1">
 <ContentTemplate>
   <asp:Label runat="server" ID="Label1" Text="Update Me!" /><br />
   <asp:Button runat="server" ID="Button1" 
     Text="Postback Update" OnClick="Button1_Click" />
 </ContentTemplate>
</asp:UpdatePanel>

 

protected void Button1_Click(object sender, EventArgs e)
{
  Label1.Text = DateTime.Now.ToLongDateString();
}

And the following is a partial postback done with the UpdatePanel when the button is clicked (notice the huge overhead involved) :

                  alt text
(source: encosia.com)

As you can see, the server is basically sending all the elements that are in the UpdatePanel back to the client.


On the other hand, here is an example that involves using ASP.Net Page Methods. Notice the response sent from the server this time (no UpdatePanels involved) :

                    alt text
(source: encosia.com)

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