Can I use UpdatePanel in MasterPage to wrap nested pages?

一曲冷凌霜 提交于 2019-12-12 07:35:46

问题


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!


回答1:


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) :

                  
(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) :

                    
(source: encosia.com)



来源:https://stackoverflow.com/questions/365183/can-i-use-updatepanel-in-masterpage-to-wrap-nested-pages

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