I have a simply site that uses a masterpage. I have a couple of pages that use that masterpage. However, the default.aspx page takes just over 15 seconds to load every time the page is loaded. The default.aspx page only contains a label and there is nothing in the page load event. All the other pages load very quickly and they all contain a lot of code in their page load event. They also use the same masterpage.
Does anyone know why this is happening ? I've set the page trace and I can see that the time between load begin and load end time is just over 15 seconds. The other more complex pages take under 2 seconds to load.
I've created a new master page and set the default.aspx page to use that and the problem still persists so I think it's the default.aspx page that has the problem. I'm not sure why as there is almost nothing in the default.aspx page.
Thanks,
Chris
Related
I want to know that when we use master page + content page then every time we request any page based on a master page then every time that same master page loads with content page.
So is it possible somethig that when we request pages then only content page must be loaded and not the master page if it is same for requested content pages.
It should only be loaded when it is different for a different content page.
Thanks
MasterPages are implemented as a control of the Page.
Asp.net pages load all the controls needed to render the page.
You will not be able to avoid loading the MasterPage control totally, if your page uses it.
If your page size is very huge, and want to reduce the size of data you send across to the client, consider using Partial rendering. UpdatePanels should get you started.
If loading your pages takes a lot of time, you should look at caching.
Asp.net has a lot of methods of caching only parts of a page.
Look at Caching portions of a page.
In asp.net, i have taken one master page, 4 four child pages and one login page, which is not in a master page. My question is when a user login redirects to the page which is has master pages, is master page execute every time or only one time after login.
Master-page-engine is just part of total page life-cycle. (see for full list of taken actions there: http://blogs.thesitedoctor.co.uk/tim/2006/06/30/Complete+Lifecycle+Of+An+ASPNet+Page+And+Controls.aspx)
So short answer - yes, each time page derived from master is shown - master is executed.
A master page is executed every time a requested childpage has it as it´s parent.
So if you go to your loginpage without master and then redirects to a page with the master, the masterpage is executed once. If you later request another page with that master or the same page again doesn´t matter. The masterpage will be executed again.
Study the ASP Page lifecycle as the masterpage has some strange behaivor and acts mote like a subcontrol. You have to be a bit careful with some events.
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...
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.
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.
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.
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:
The whole masterpage isn't useful anymore. The content around your iframe is the "masterpage".
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.
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.
I have a page which needs to terminate execution of it's code (which is run at render) but not stop the execution of the MasterPage.
The problem is this,
page 'Default.aspx' uses the masterpage 'MasterPage1.aspx'. The code in Default.aspx checks a certain condition and if found to be true, Default.aspx needs to stop executing, but render the rest of the MasterPage.
I found that if I call response.end() in default.aspx, the rendering of the MasterPage is also terminated.
So what I am looking for is an alternative which stops execution in default.aspx, but still renders the rest of the MasterPage.
Thanks :)
Rather than returning a master page without any content, why not use Response.Redirect to go to an error page (which could have the same master page)?
You can use Server.Transfer() to go to a new page, and avoid a redirect.
I have a simple setup with the master page housing some controls used by all child pages.
I found when moving to new pages the master page page loads event fires as a non post back and read the solution was to store it's current values somewhere for retrieval. Ok all done.
The child page uses these values to run a report. When I switch to a new report, all is well. If I change the values in the master page the master page and the sub page load events fire.
The load event for the sub page fires first, picks up the values from the master page which are still the old values and then finally the master page events fire and all the new values are stored. The report hasn't changed as it still ran from the old values.
I can't really see a way around this. All you ever hear is that master pages are a saving grace but I swear i've never jumped through so many hoops to get a page to load correctly.
And now this!
Anyone see a plan to resolve it?
Populating the controls during the Masterpage's Init will solve your issue from the sounds of it.
http://msdn.microsoft.com/en-us/library/dct97kc3.aspx
An alternate approach would be to have a public sub in the content page(s) that you can call from the masterpage during load which in effect acts as an alternate to the page load event.
A slightly more indepth look at the page lifecycle when using masterpages:
http://weblogs.asp.net/ricardoperes/archive/2009/03/08/asp-net-page-events-lifecycle.aspx