I wanted to know if the MVC framework can leverage the Nested Master Page? If so does anyone have some info on how to achive this?
We use nested master pages frequently, in order to seperate layout from standard includes and site wide markup, like so:
Site.Master:
<%# Master Language="C#" AutoEventWireup="true" Inherits="System.Web.Mvc.ViewMasterPage<PageViewModel>" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="language" content="en">
<title><asp:ContentPlaceHolder ID="Title" runat="server"><%= Model.Page.Title %></asp:ContentPlaceHolder></title>
<% Html.RenderPartial("Head"); %>
<meta name="robots" content="index, follow">
<meta name="robots" content="noodp">
<asp:ContentPlaceHolder ID="ExtraHead" runat="server"></asp:ContentPlaceHolder>
</head>
<body >
<asp:ContentPlaceHolder ID="MainContent" runat="server"></asp:ContentPlaceHolder>
</body>
</html>
then have a another master using the Site.Master,
Standard.Master:
<%# Master Language="C#" AutoEventWireup="true" Inherits="System.Web.Mvc.ViewMasterPage<PageViewModel>" MasterPageFile="Site.Master" %>
<asp:Content ContentPlaceHolderID="ExtraHead" runat="server">
<asp:ContentPlaceHolder ID="ExtraHead" runat="server"></asp:ContentPlaceHolder>
</asp:Content>
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
<asp:ContentPlaceHolder ID="MainContent" runat="server"></asp:ContentPlaceHolder>
</asp:Content>
Yep. I just saw a blog post about this at: http://jeffreypalermo.com/blog/asp-net-mvc-and-the-templated-partial-view-death-to-ascx/
Very cool stuff.
Related
I know there is something I am missing on this
But am unable to figure out that
I have this master page:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Mains.master.cs" Inherits="Sportsstop.Mains" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Sports Stop</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
N there is this Child page which should merge with the above master page:
<%# Page Title="" Language="C#" MasterPageFile="~/Mains.Master" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="Sportsstop.Home" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server" >
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
Your textbox should be in child page, inside ContentPlaceholder1. I think that the one in master page is ignored.
If you want to have TextBox in master page, it cannot be inside ContentPlaceholder
Think about placeholder as a place, where the content from child page gets injected
I can't get my child page to pick up styles defined in my master. Here is what I did:
I created a stylesheet Main.css in the root of my app
body {
background-color:red;
}
I created a Master Page Site.Master in the root of my web application
<%# Master Language="VB" AutoEventWireup="false" CodeBehind="Site.master.vb" Inherits="WebApplication1.Site" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
<link href="Main.css" rel="stylesheet" />
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
Master Page`
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
This shows up with a red background fine in the designer
I created a child page WebForm.aspx in the root of my app
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
Child Page Contents
</asp:Content>
But this doesn't show a red background either in the designer or at runtime. When I view source there is no css declaration in the file, yet it is picking up the master page because it displays "Master Page Child Page Contents"
Restructure your Master Page to look like this:
<%# Master Language="VB" AutoEventWireup="false" CodeBehind="Site.master.vb" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<link href="Main.css" rel="stylesheet" type="text/css" />
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
Master Page`
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
You need to link the stylesheet in the head tag, not the ContentPlaceHolder one.
Replace this
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
<link href="Main.css" rel="stylesheet" />
</asp:ContentPlaceHolder>
with
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="Main.css" rel="stylesheet" />
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
The link to your css sheet is inside a content place holder.
I have a page that uses a master page.
I disabled viewstate on the page (not the master page), and I didn't notice that the viewstate was reduced.
Curious if the masterpage setting will override it?
In my testing setting EnabledViewState = "False" will not reduce the page's view state while setting ViewStateMode="Disabled" will decrease the viewstate size
Master Page
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="ViewStateTest.master.cs" Inherits="Sample.ViewStateTest" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
Child Page
<%# Page Title="" Language="C#" MasterPageFile="~/ViewStateTest.master" AutoEventWireup="true" CodeBehind="ViewstateTestPage.aspx.cs" Inherits="Sample.ViewstateTestPage" ViewStateMode="Disabled" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:TextBox runat="server"></asp:TextBox>
</asp:Content>
Hi:
I am new to asp.net,so I meet some problem about the master page.
I define a master page and set some css and js within it:
<%# Master Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server" >
<title>Master page title</title>
<script xx.js></script>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td><asp:contentplaceholder id="Main" runat="server" /></td>
<td><asp:contentplaceholder id="Footer" runat="server" /></td>
</tr>
</table>
</form>
</body>
</html>
Then my child page:
<% # 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>
When I start the child page,I found the xx.js is not included in this page,what is the problem?
<head>
<script type="text/javascript" src="xx.js"></script>
</head>
This "xx.js" should be in your appl
I have calender datetimepicker jquery.
when I am calling this in simple aspx page then its working fine but when i am calling in the page where master page attach then its not working.
Here's the code that I am using:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default11.aspx.cs"
Inherits="Default11" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="ui.all.css" rel="stylesheet" type="text/css" />
<link href="demos.css" rel="stylesheet" type="text/css" />
<script src="jquery-1.3.2.js" type="text/javascript"></script>
<script src="ui.datepicker.js" type="text/javascript"></script>
<script src="ui.core.js" type="text/javascript"></script>
<title>Untitled Page</title>
</head>
<script type="text/javascript">
$(function() {
$("#txt").datepicker();
});
</script>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txt" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
That is working fine.
But when I am calling like this then its not showing calender
<%# Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="CAL.aspx.cs"
Inherits="admin_CAL" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CPHMain" Runat="Server">
<link href="ui.all.css" rel="stylesheet" type="text/css" />
<link href="demos.css" rel="stylesheet" type="text/css" />
<script src="jquery-1.3.2.js" type="text/javascript"></script>
<script src="ui.datepicker.js" type="text/javascript"></script>
<script src="ui.core.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("#TextBox1").datepicker();
});
</script>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:Content>
ASP.net changes the ID of your control - you see it clearly by checking the source of your generated page. Try:
$("[id$='TextBox1']").datepicker();
This checks for an element who's ID ends with "TextBox1".
Alternately, you can solve this at server side:
$('#<%= TextBox1.ClientID %>').datepicker();
Is there an element with an id of TextBox1? If you open the page in Firefox and use the Firebug console what kind of error is it spitting out?
You need to be a bit more informative for us to be able to help you.