Reload only Content Pages Inside the Masterpage - asp.net

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.

Related

Not able to add form tag inside Content Page

I have a Master Page and a Content Page. I have Check In Check Out small form in Master Page and I have a Contact form in Content page. But while running the website, I am getting the error which says:A page can have only one server side form tag. When I remove the form tag from the Content Page. Then,it says the Textbox should be placed within a form tag. But I want both the forms,since both are necessary. So please help me so that I can have both the forms.
There can be only one <form> tag on the whole page, that is just how webforms work. In your case it is in the master page. The pages using the Master do not and should not have <form> tags.
But from your question it seems that you think you are using master pages, but are actually not. See this page as to how the .aspx pages are supposed to look with master and child pages.
https://learn.microsoft.com/en-us/aspnet/web-forms/overview/older-versions-getting-started/master-pages/creating-a-site-wide-layout-using-master-pages-cs
It is not possible to add more than one form in a single aspx file. Otherwise try to use iframe in that page.Inside the iframe we can use another aspx page.

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)"/>

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

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.

how to show aspx page in contentplaceholder of masterpage

I have a master page in my website.
I have two contentplaceholder on that master page.
In one contentplaceholder i have some links on which click I want to redirect
to the corresponding page in the second contetplaceholder on the same master page.
how can i do this....?
pls help ..?
I think you may have missed something here. When you use master pages you have content pages instead. The content page defines the area defined by the content place holder in your master page. When you create a content page you use the contentplaceholder tags to show your page content within the master page. It might be worth reading up the master pages tutorials on the ASP.NET website.
I don't see a problem here. Just make the .aspx pages use the same master page and set the link locations to .aspx pages.
From what it sounds like, you'll want to use a sitemap instead of the first contentplaceholder. Here is a description of them: http://msdn.microsoft.com/en-us/library/yy2ykkab.aspx

Resources