load only content page - asp.net

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.

Related

How to avoid refreshing of masterpage while navigating in site?

In my website, I have created a masterpage and attached all of my pages to it.
My masterpage structure contains a header and a footer. On the left it has a treeview control, which i have attached to all my pages, and on the right there is a contentplaceholder to show the content of respective pages.
My problem is that when I click any link in the treeview it refreshes the whole masterpage and open the respective page. I wish to avoid this refresh. Means it should show the contents of page on right side contentplaceholder without refreshing the whole page.
I have seen people suggesting to use iframes. But for using iframes I shall have to restructure my website. Is there any other solution than iframes and with minimal changes to the work that I have done?
You will probably want to look at using AJAX to stop this from happening. You will want to read up on using an UpdatePanel. Below are some good articles that goes over this:
http://geekswithblogs.net/ranganh/archive/2007/05/11/112405.aspx
http://msdn.microsoft.com/en-us/library/bb399001.aspx
You also have the option of using jQuery to handle your AJAX calls. While I typically prefer the use of jQuery when using AJAX, I am not sure I would use it in your situation. If you would like to look at what it offers take a look at these links:
http://api.jquery.com/jQuery.ajax/
http://sixrevisions.com/javascript/the-power-of-jquery-with-ajax/
You could put the content you wish to change inside an asp:UpdatePanel that way that will be the only thing that is repainted (it uses AJAX under the hood):
http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel.aspx
The master page class derives from the UserControl class and the master page is like a child control. So we can say that master page is not a true page, when a page loads we can notice the navigation URL in the address bar is the content page's but not the master page! so we cannot refresh a content page without refreshing master page.
there is one way to avoid flickering the page by adding the code in < Head > section in the masterpage.
<meta http-equiv="Page-Enter" content="blendTrans(Duration=0)"/>
<meta http-equiv="Page-Exit" content="blendTrans(Duration=0)"/>

Reload only Content Pages Inside the Masterpage

I have more than 100pages in my project & a single master page for all this. My masterpage has links to different pages. I want to change only the ContentPages( Child Pages) & my masterpage should not get reloaded.
For Example:
My Master page is : SiteMaster.master
Child Page1: Add.aspx
Child Page2: Sub.aspx
When I execute, Add.aspx comes inside the SiteMaster.master. Know, When I click the sub.aspx link inside the Add.aspx, only add.aspx page should be changed & sub.aspx must be loaded. I don't want to reload the master page.
If possible, please post some examples or links.
Your expected behavior is not exactly how master pages work. There may be ways to achieve a no postback solution in this scenario but the easiest one would be to use an <IFrame /> (which is usually frowned upon)
Master page is part of your pages. It's not loading separately.
Simple explanation:
ASP.NET engine takes your aspx and puts it inside the master page and then renders it as one page, then serves it to user.
If this is not what you want and you want that only content of your master page be loaded, then you should not use master pages at all! It's against nature of master pages. they act like skins for aspx pages.
Search for HTML IFrame tag and don't use master page.
P.S: IFrames are not used widely in this days.

Put Script Manager in master page

is it right to put script manager in master page ?
It isn't wrong, as such.
Really depends on your requirements.
If you need to use scripts in several pages that use the same master page, use ScriptManager in the master page.
Just keep in mind that you can only have one ScriptManager in the whole loaded page, so you can't add one in content pages as well.
See this article on MSDN for an example (Using the ASP.NET UpdatePanel Control with Master Pages).

Loading ScriptManager only once either from Master page or Content page

I have an web application of 200 web pages and all has a single master page. Most of the content pages use AJAX controls so most of content pages has its own ScriptManager. Now I have a requirement to add a link with HoverMenuExtender control and for that I need to put ScriptManager in the Master page, but it is working only in the content pages where there is not ScriptManager.
All the other content pages which has ScriptManager throws the error Only one instance of a ScriptManager can be added to the page. I don't want to work on most of the content pages again to remove ScriptManager.
Is there any easy way to do this something like coding in Master page which decides if there is already ScriptManager already, then don't load it.
Take a look at ScriptManagerProxy. This is what I think you need.

Stop Master page refreshing while navigating between pages?

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.

Resources