Ive been building a website with 2 pages and 1 master page. The master master page works as a "Menu". The two pages inherits from the master page and have some content on them.

On Page1 I have a link to Page2. Once I click on the link Page2 (and master page) loads.

Pretty straight forward I guess. But my question is now:
The master page ofcourse reloads everytime I go to a new page and thereby the entire site "flicks" for short moment to switch to the next page. Is there some "best practice" for keeping the master page(the menu) on the page while only loading the content?

I still want to split the two pages up in Page1.aspx and Page2.aspx and not having all my content in 1 page with panels showing the content of page1 and another panel showing the content of page2 etc.
Should I use some sort of control that has the pages inside them or is this just a stupid question and I shouldnt be bothered by the entire page flicking as this is just normal "web behaviour"?

Hope you can help :)

  • I would recommend looking at ASP.NET MVC, ASP.NET WebForms is somewhat outdated – Mithir May 9 '12 at 13:11
  • @Mithir I fail to see how WebForms is outdated, some feel the MVC approach may be too heavy for their needs, especially for smaller projects. – maple_shaft May 9 '12 at 13:27
  • 1
    I still recommend looking at it. – Mithir May 9 '12 at 13:30

You seem to be looking for a site the loads new data and updates the HTML directly - this is not how ASP.NET webforms work by default. When you go to a new page, it needs to load from scratch.

To achieve what you want, you would need to use AJAX to query the web server for the data/template and update the page.

Webforms can work this way - using the UpdatePanel and related classes and javascript.

  • I have been working with updatepanel before but im not sure how to implement it in this situation. I mean, if I have a link to Page2.aspx and click it, the entire page as well as the master page would still need to be reloaded. If I however were just navigating Page1.aspx only, I would ofcourse use the updatepanel to avoid the entire page to reload. But again, how do other people use the master page, do they just live with the "flickering" between page reloads and thats it, or is there some other smart way :) – mRf May 9 '12 at 13:16
  • 1
    @Thomas - UpdatePanel does not work like that. You have to accept that your page will "flicker" when you move between pages (as the browser needs to load, parse and render your HTML) – Oded May 9 '12 at 13:20
  • Okay, i thought so :) But what about the solution to use some sort of control/iframe that shows the contentpages so that the master page does not have to reload all the time? Do people that sort of thing or is that just really bad practice vs. flickering – mRf May 9 '12 at 13:28
  • @Thomas - Again, most people use AJAX for that - without master/content pages. You don't have to use UpdatePanel - there are many many ways to do this. – Oded May 9 '12 at 13:32
  • Hmm, maybe I just dont know enough about how to design a website that is easy to navigate. Can you maybe explain or give a link where I can get an idea of how to design a website using ajax in a proper way. – mRf May 9 '12 at 13:41

Oded's excellent answer is correct, the UpdatePanel will allow you to make use of AJAX so that contents within the UpdatePanel can be rerendered without refreshing the entire page within the browser, but then this won't cause page navigation to be magically AJAX'ified.

Invoking a browser action where you request another page be ASPX page be accessed will result in the server navigating to another page.

I think you fundamentally misunderstand how a MasterPage works. It is not a single web page with injectable AJAX enabled child pages preventing the need for browser navigation. It is merely a template that Page1.aspx and Page2.aspx both use, but ultimately the server will still recognize that these two pages are seperate navigable items.

I think you should maybe look at how to develop a UserControl. These can be defined in markup and code behind as if they were a seperate page, and they can be placed inside of an UpdatePanel to refresh the components in question without have to do a full page postback.

  • Thanks for the answer :) I dont know if you can answer this question, but how do people "normally" design navigation? I mean, "master pages" arent outdated right? So if other people are using the same principle as me, they just arent concerned with the "entire page refresh"? I dont actually mind that the whole page is reloading but I just want to know if im doing this nagivation thing in a proper way or if I could be doing something better – mRf May 9 '12 at 14:41
  • @Thomas This is entirely subjective and based on the type of user experience defined by your requirements. Seperate pages for navigation result in the "flicker". Having many different user controls within an UpdatePanel in a single page however will result in an enormous page that will not perform well. Keep in mind that even during asynchrnous page requests, the entire page control state and view state is communicated back and forth with the server, and the server lifecycle events still occur for all controls. Having everything in a single page will most (cont...) – maple_shaft May 9 '12 at 15:08
  • (cont...) certainly perform worse than many small navigable pages. Most people however use a mixture of both where appropriate. If I were to have Page1.aspx be a step-by-step wizard for example, then I might want each step to be an asnychronous operation, however for a search list, I probably want that on a seperate page altogether. Make sense? – maple_shaft May 9 '12 at 15:10

Another approach is to drop the concept of a "master page" with navigation and 2 content pages.

Maybe just think of it as 2 pages, which both contain content and navigation where the navigation might be similar on both pages.

An html page is a document and both navigation and content are part of that document. Without the navigation, you can't find other pages and without content there's nothing too find.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.