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

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)

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

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>

How to add master page to already created webform?

I have a asp.net webform application. Now I have to add master page in this application, but I don’t know how to merge or add new created master page with old webforms? How to handle html in webforms like <head> , <body> ? Any link in this regard will be helpful.
1- Define the fixed elements in your design, and put them inside the newly created master page
2- Define the dynamic ones, and add asp:ContentPlaceHolder for them ( most commonly one for HEAD, one for main content in your BODY , and one for side content "if applicable")
<asp:ContentPlaceHolder ID="CphHead" runat="server">
</asp:ContentPlaceHolder>
3- In your pages, add MasterPageFile="~/MASTER_PAGE_PATH" inside the Page directive.
4- Add asp:Content sections inside your pages which will hold the dynamic content in your pages, and don't forget to reference the correct ContentPlaceholder ID.
<asp:Content ID="HeadContent" ContentPlaceHolderID="CphHead" runat="server">
// Your content goes here...
</asp:Content>
5- Copy your page content inside these asp:content sections, and BOOOOM....you are done.
at the top of the new page in the '<%# page #>' tag add 'MasterPageFile="~/Site.Master"'
then add the needed placeholders
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
</asp:Content>
of course modify these to the names you are using
you can add the content holder tag in master page. So when you add 'MasterPageFile="~/Site.Master"' then you able to add content of other pages.

ASP.NET Different Layouts within 1 Site

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>

Resources