ASP.NET Different Layouts within 1 Site - asp.net

A client has an ASP.NET website with master pages and a layout directory.
What we need is 2 different layouts on the site. Can I easily have two layouts with different master pages on the same site?
What's the best way to do that?

See Setting an ASP.NET Master Page at runtime. You can set any page to use any masterpage programmatically at runtime.

Yes. Just create two different master pages and point the corresponding aspx pages to the desired masterpage.
Example:
page1.aspx
<% # Page Language="C#" MasterPageFile="~/Master.master" Title="Content Page 1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
Main content.
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Footer" Runat="Server" >
Footer content.
</asp:content>
page2.aspx
<% # Page Language="C#" MasterPageFile="~/secondary.master" Title="Content Page 2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
Main content.
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Footer" Runat="Server" >
Footer content.
</asp:content>

Related

How to show an outside website like google or bing within a master page

I have created a website using a master page. One of the links within the master page is for Googles website. I can display the google website within the master page by inserting the website within a Iframe, but the problem is when I do a search in google and I click on the links some of the links within google do not open. After some reading I find that some websites do not allow their sites to open within an iframe "You have to check for HTTP response header X-Frame-Option of those sites. if its value is "DENY or SAMEORIGIN", then you can not load those website in the iframes.".
So does anyone know of another way to display an outside website within a master page?
This is my content page
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="Google.aspx.cs" Inherits="OnCallWeb.Google" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<p>
<iframe src="https://www.google.com/webhp?igu=1" style="width:100%;height:700px;"></iframe>
</asp:Content>
This is on my master page.
<li>Google</li>
Found Google no longer supports Iframes

Is there any possibility to add master page for more then one existing .aspx page?

I already made update.aspx page and view.aspx page now I want to assign master page that to these pages...can someone help me out ?
Create new master page names Site.Master, move everything you want from update.aspx into master, so probably Head section html content, and then in the body put the placeholder:
<asp:ContentPlaceHolder runat="server" ID="MainContent" />
Now when "shared" master content is moved from your update.aspx/view.aspx, you just need to wrap everything that's left in those pages into this:
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
your update.aspx page content
</asp:Content>
In first line of your page you should have something like <%# Page ... attributes ... %>, add new attribute that points to the master page: MasterPageFile="~/Site.Master"
For the reference, create new WebForms project and you'll get few sample pages. See how should a HTML content in the master page look like, and how to wrap page content of you aspx page.
End result should look something like this:
Site.Master
<html><head>...</head>
<body>
some master body html content
<asp:ContentPlaceHolder runat="server" ID="MainContent" />
more html here
</body>
<html>
Then the page:
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
your update.aspx page content
</asp:Content>
i suppose your master page is Main.Master
the first step
in the update.aspx page and view.aspx page (at the top )
make MasterPageFile attribute = "~/Main.Master" this is the code
<%# Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="update.aspx.cs"
the second step
remove the head and title and body and html tags from the update.aspx page and view.aspx page
and put tow content two content place holders (the same in the master page) in your pages(update.aspx and view.aspx)
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"></asp:Content>
the previous content place holder represents the head of this page you can put in it any css or java script code or references
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"></asp:Content>
second placeholder represents the body of this page you can put in it the body of your page(update.aspx)

Content page not displaying images

I have a project with a master page at the root level and multiple content pages which are at the root level as well. Everything has been looking fine until I created a new folder and put a new content page in that folder. None of the images are displaying for that particular page. I'm sure its something simple that I'm missing.
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="SupertonesInstallation.aspx.cs" Inherits="Articles_SupertonesInstallation" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Home" Runat="Server">
content
</asp:Content>

Error on Adding Master Page.

I have a using ASP.net C# firstly I have created a webform FrmFirst.aspx. Then I have created a master page. Now I have to add my first page to master page then I am facing the same error :
I am using this code to add my first page to Master page
<%# Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPage.master" CodeFile="FrmCustomerMaster.aspx.cs" Inherits="FrmCustomerMaster" %>
Tell me my Problem !! Thanks ....
You need to change your body to content sections. The master page works with contentplaceholders: your content pages need to provide the content for these placeholders
see LINK
if your master page contain this code
<asp:contentplaceholder id="Main" runat="server" />
your page that Inherits from master should have
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
</asp:Content>

Style sheets only for the content page of a Master page in asp.net

I have a master page which has 10 content pages linked to it.
Now a CSS file attached to the Master page gets applied to the content page on its own.
If however, I want a different CSS file only for one of the content pages (and none of the master page CSS should apply to it). How to do it??
You can add that style to a placeholder of the specific page not the masterpage
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="Detail.aspx.cs" Inherits="Test.Detail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<link href="<%= Page.ResolveUrl("~/styles/style.css")%>" type="text/css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>

Resources