I don't understand the scope of the variables in my .Master pages - can anyone assist?
In the example below settings cannot be seen in either usage following its instantiation:
<%# Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<% var settings = new SettingRepository(); %>
<!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">
<meta name="description" content="<%: settings.metaDescription %>"/>
<title>
<asp:ContentPlaceHolder ID="TitleContent" runat="server" /> - <%: settings.pageTitle %>
</title>
...
In the example below settings can only be seen in the FIRST usage, but not the second:
<%# Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<!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">
<% var settings = new SettingRepository(); %>
<meta name="description" content="<%: settings.metaDescription %>"/>
<title>
<asp:ContentPlaceHolder ID="TitleContent" runat="server" /> - <%: settings.pageTitle %>
</title>
...
According to me what ever variable you use in Master page it is accessible to its XAML file and cs file.
You can access it in its content pages like this:
String variable=((MasterPageName).this.Master).variable;
Use #MasterType directive, as explained here:
http://msdn.microsoft.com/en-us/library/c8y19k6h.aspx
Related
I am trying to follow the Microsoft instructions on how to create a user control
my aim is to convert the .aspx file
<%# Page Language="C#" Title="Customize the queue UI" %>
<%# Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
</head>
<body>
<form id="Form1" runat="server">
<CuteWebUI:Uploader ID="uploader1" runat="server">
</CuteWebUI:Uploader>
</form>
</body>
</html>
I tried the following
<%# Control CodeBehind="kgfileUploader.aspx.cs" Inherits="SampleUserControl" Language="C#" %>
<%# Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader, Version=3.0.0.0, Culture=neutral, PublicKeyToken=bc00d4b0e43ec38d" %>
<h3> <u>User Control</u> </h3>
<CuteWebUI:Uploader ID="uploader1" runat="server">
</CuteWebUI:Uploader>
But I get an error "Control directive is not allowed in .aspx file"
Where have I gone wrong?
I've just created a label in default.aspx page and created a skin in skinfile.skin. I've put the skin file in App_Themes folder, i've included the reference to that file in the < link > tag and i've mentioned the skin id for that label.
so according to the code, the label should have background as black and text as orange, right? But nothing's happening.
What i'm doin wrong here?
Here's the code:
Default.aspx:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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></title>
<link rel="stylesheet" type="text/css" href="App_Themes/SkinFile/SkinFile.skin" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label" SkinID="LabelSkin"></asp:Label>
</div>
</form>
</body>
</html>
SkinFile.skin:
<asp:Label runat="server" SkinID="LabelSkin" BackColor="Black" Color="Orange">
</asp:Label>
i got this thing fixed. all i had to do was set the 'theme' attribute in the <%# Page.... Theme= "SkinFile" %> statement as the name of the folder in which the skin file is... ^_^
The title displays properly in all other search engines, it only does this with Google's search:
The site (www.ClearspanInc.com) has been up for awhile, and has had more than enough time to be crawled. We are using ASP.net.
<!DOCTYPE html>
<html lang="en">
<head id="Head1" runat="server">
<meta charset="utf-8" />
<title>******* - <%: Page.Title %></title>
<asp:PlaceHolder ID="PlaceHolder1" runat="server">
<%: Scripts.Render("~/bundles/modernizr") %>
</asp:PlaceHolder>
<head>
<title>My Title</title>
</head>
Try this inside the #Page:
<%# Page Title="Home Page" %>
Or inside the Page_PreRender you can add Page.Title = "";
I have a site with a few pages, and I'd like the titles of the pages to be:
Foo - 1st Page
Foo - 2nd Page
Foo - 3rd Page
I've created a Master Page with the following code:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Foo.master.cs" Inherits="Foo" %>
<!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>Foo - <asp:ContentPlaceHolder ID="SubTitle" runat="server"></asp:ContentPlaceHolder></title>
</head>
<body>
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</body>
</html>
And then each page looks like this:
<%# Page Language="C#" MasterPageFile="~/Foo.Master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="SubTitle" runat="server">1st Page</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
Page 2
</asp:Content>
When I load the page in the browser I expect the title to be Foo - 1st Page, but it's just 1st Page.
The html source is :
<!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><title>
1st Page
</title></head>
<body>
Page 2
</body>
</html>
What am I doing wrong?
You do not want to remove runat="server" from head; it'll create other problems.
Use the following method which is a default method in ASP.Net Web Forms Application in Visual Studio 2012.
<!-- Master Page -->
<head runat="server">
<title>Foo - <%: Page.Title %></title>
</head>
<!-- Content Page/xxx.aspx -->
<%# Page Title="Home Page" ...>
Turns out this question had already been asked: ASP.NET: Having common Page title in master page with each page adding page-specific title?
After reading the answers there I found that removing runat="server" from the head element in the Master Page did the trick.
I have a aspx page that begins like this:
<%# Page Language="C#" MasterPageFile="~/Main_MP_Teacher.master" AutoEventWireup="true" CodeFile="default.aspx.cs"
Inherits="Teacher_default" Title="Teacher Page" %>
I want to include html in this page also but when I put in the first line
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/strict.dtd">
I get a parse error. What am I doing wrong?
The parser error is probably because you're putting something other than <asp:ContentPlaceHolder> in the root of your ASPX page.
If you're using a MasterPageFile then the <!DOCTYPE should be at the start of the MasterPage.
This is unless you have a <asp:ContentPlaceHolder> right at the start of the MasterPage, which you can put the <!DOCTYPE into it.
MORE INFORMATION
The <!DOCTYPE should always be the very first thing in the HTML file, so normally your MasterPage would look something like this...
<%# Master Language="VB" CodeBehind="MyMaster.master.vb" Inherits="dev.MyMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/strict.dtd">
<html>
<head>
<asp:ContentPlaceHolder runat="server" id="myHeader"/>
</head>
<body>
<form id="form1" runat="server">
<asp:ContentPlaceHolder runat="server" id="myBody"/>
</form>
</body>
</html>
If for some reason you wanted to have a page specified doc type, then you could add a new placeholder at the start, with a default value...
<%# Master Language="VB" CodeBehind="MyMaster.master.vb" Inherits="dev.MyMaster" %>
<asp:ContentPlaceHolder runat="server" id="myDocType">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/strict.dtd">
</asp:ContentPlaceHolder>
<html>
...
</html>
And then in the page you want to override put the following (by NOT overriding, the original will be output instead)...
<%# Page Language="vb" MasterPageFile="MyMaster.master" Codebehind="MyPage.aspx.vb"
Inherits="dev.MyPage" Title="My Page" %>
<asp:Content runat="server" ContentPlaceHolderId="myDocType">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
</asp:Content>
...