Stop Master page refreshing while navigating between pages?
Asked Answered
L

3

8

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...

Lotetgaronne answered 21/4, 2010 at 7:46 Comment(0)
S
6

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.

Solder answered 30/4, 2010 at 10:43 Comment(1)
Thanks for your post, I tried the first solution without putting all the controls in the page, instead of that I created the controls at run time, this much faster and better,:( finally I shifted back to Frames because a lot of problems happened in Java Script code. Now Frames solved this issue for you thanks for all.Lotetgaronne
H
3

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.

Hamrnand answered 21/4, 2010 at 7:58 Comment(5)
Thanks, actually I solved the refreshing problem by using frames, but I'm looking for another way to solve this issue, imagine that you have Navigation bar on the left side and Pages on the right side of the page, I want when clicking any Item in NavBar to don't post back the hole page.Lotetgaronne
It isn't a postback. You simply request another url and the server returns you a bunch of html that is rendered by the browser. What is your biggest problem/concern when it comes to the whole refreshing?Hamrnand
The Problem that it's reloading Logo and Navigation Bar and Footer, Causing slow in the website, The requirement is to make the website as much we can as windows application, and this can't be done without fully Ajax supporting.Lotetgaronne
That make sense. In that case working with iframes doesn't really solve your "problem" then. The content in the iframe will be loaded as well. That can cause a white frame if the site or the connection is slow.Hamrnand
Thanks for your time, I'm working know on converting the web pages to UserControls and load the controls by using LoadControl Function inside Update Panel, it seems good but there are a lot of difficulties and problems I'm trying to solve. IFrame is good I saw that Gmail is using it for solving this issue.Lotetgaronne
W
2

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.

Whitebeam answered 21/4, 2010 at 7:56 Comment(1)
You can use Tabs control, for example. asp.net/ajax/ajaxcontroltoolkit/samples/tabs/tabs.aspx But it depends on the effect you wan to accomplish, and the visual layout of the application.Whitebeam

© 2022 - 2024 — McMap. All rights reserved.