I am working on a page which is using a Master page for some default design,
I need some css class to be added to the conent page, which we add normally in script tag in normal pages,
My question is how to add some css content in a page which is using Master page,
Thanks,
Vishal.
In your master page you can add a content area within the <head> block. We call ours "HeadContent".
Our master page's head block looks like this:
<head>
...
<asp:ContentPlaceHolder ID="HeadContent" runat="server" />
</head>
From your content pages you can then include custom scripts/css etc:
<asp:Content runat="server" ID="Head" ContentPlaceHolderID="HeadContent">
<script type="text/javascript" src="<%= Url.Content("~/scripts/gradebook.js") %>"></script>
<style type="text/css">
#import url('<%= Url.Content("~/styles/gradebook.css") %>');
</style>
</asp:Content>
You could add a ConentPlaceHolder in the head area of your masterpage like this:
<head>
....
<asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server" />
</head>
In your content page you just need a content control:
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="Server">
// Put your css stuff here
</asp:Content>
Related
I have a Master page that have these ContentPlaceHolder:
<asp:ContentPlaceHolder ID="title" runat="server">
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="contentTitle" runat="server" ></asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="content" runat="server">
</asp:ContentPlaceHolder>
when I add these codes for jquery in<head> part of master page:
<script type="text/javascript" src="script/jquery-2.0.1.min.js" />
<link href="script/jquery.contextMenu.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="script/jquery.contextMenu.js" />
and create new aspx file that use that master page ;
<%# Page Title="" Language="C#" MasterPageFile="~/Default.Master" AutoEventWireup="true" CodeBehind="Bed.aspx.cs" Inherits="Zhotel.Lists.Bed" %>
<asp:Content ID="Content1" ContentPlaceHolderID="title" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contentTitle" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="content" runat="server">
</asp:Content>
when I want to view Design part of file it show me this error:
and when I remove script tags then no more this error occurs.
How can I use script tag that this error not shown?
Add </script> to end of jquery definition, like this:
<script src="script/jquery-2.0.1.min.js" type="text/javascript"></script>
<script src="script/jquery.contextMenu.js" type="text/javascript"></script>
place your scripts outside of contentplaceholder 'title' in head section and make sure that your page has correct reference to your masterpage and also make sure that you are placing the contentplaceholders in their appropriate places
I've an aspx page that extends a master page. I want to change aspx page's document mode. I'd like to put this line to aspx page. But It doesn't allow. I don't want to put this code to master page's head want only change the page's document mode. Can somebody help me?
<meta http-equiv="X-UA-Compatible" content="IE=9" />
You need a placeholder in your masterpage:
<head>
<asp:ContentPlaceHolder id="plhHead" runat="server"/>
</head>
If your <html/> tag has no runat="server", you need to apply it to the <head/> tag like KPL did.
And then fill it in the client page like you do with your main content placeholder:
<asp:Content ContentPlaceHolderId="plhHead" runat="server">
<meta http-equiv="X-UA-Compatible" content="IE=9" />
</asp:Content>
Place a ContentPlaceHolder in the head section of your Master Page:
<head runat="server">
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
Now from your .aspx page, you can add custom content in the head section:
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<meta http-equiv="X-UA-Compatible" content="IE=9" />
</asp:Content>
As an alternative to placing a ContentPlaceHolder in the Master page, you can do this:
// Programmatically add a <meta> element to the Header
HtmlMeta keywords = new HtmlMeta();
keywords.Name = "X-UA-Compatible";
keywords.Content = "IE=9";
Page.Header.Controls.Add(keywords);
Hai guys,
How to include inline jquery scripts used in an aspx to a separate js file with asp.net master pages
Your masterpage can have a script link to the core Jquery file:
<html>
<head runat="server" >
<title>Master page title</title>
//link to Jquery script
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<asp:contentplaceholder id="Head" runat="server" />
</head>
<body>
.
<asp:contentplaceholder id="Main" runat="server" />
.
</body>
ASPX page can have other script links specific to the page only
<% # Page Language="C#" MasterPageFile="~/Master.master" Title="Content Page 1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Head" Runat="Server">
//other scripts specific to this page only
<script type="text/javascript" src="js/jquery.plugin.abc.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Main" Runat="Server">
Main content.
</asp:Content>
I have Master page and some content pages.
I want to assign different css file to each of the content pages.
(without using themes)
How can I do that?
I did that once by adding a header-placeholder in the master-page, and explicitly specifying the css in the content-pages.
In the Master:
<head runat="server">
<title></title>
<link href="~/css/common.css" rel="stylesheet" type="text/css" />
<!-- loads of other stuff / -->
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
and in the Content:
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<link href="../css/SomeContent.css" rel="stylesheet" type="text/css" />
<script src="../js/SomeJsToo.js" type="text/javascript"></script>
</asp:Content>
If you're using visual studio 2008, you're going to have a real easy time. First make a master page like this:
<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>
</body>
</html>
Now make a content page based off of this master page:
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>
Now in the Content1 placeholder you just place the stylesheet that you would like to have applied to that page.
That's it. Hope this works for you.
Use an external master CSS file for all pages using:
<link rel="stylesheet" type="text/css" href="master.css" />
Then you can use embedded CSS on the individual content pages using the style tag, e.g:
<style type="text/css">
h1 {color:red}
p {color:blue}
</style>
I have tried many of the above ways but still getting error. Finally i use the following codes on the page load and it works fine:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim css1 As New HtmlLink
css1.Href = ResolveUrl("report.css")
css1.Attributes("rel") = "stylesheet"
css1.Attributes("type") = "text/css"
css1.Attributes("media") = "all"
Me.Page.Header.Controls.Add(css1)
End Sub
In my view, I have included the Master page as follows:
<%# Page Title=""
Language="C#" MasterPageFile="~/Views/Shared/Mall.Master"
Inherits="System.Web.Mvc.ViewPage<DomainModel.Entities.Seller>" %>
And in my Mall.master file, I add a link to include a general css file
<link rel="Stylesheet" href="../../Content/MallMaster.css" type="text/css" />
However, I need another more specific purpose css file CheckOut.css in my view. Since the style defined in Checkout.css only applies for one page, I do not want to include the file in the master page. Is there any way to include the file in my view?
You should add a new content () placeholder in your MasterPage and then in your view you can add another css to this placeholder.
<asp:ContentPlaceHolder ID="head" runat="server">
<title></title>
<link rel="Stylesheet" href="../../Content/MallMaster.css" type="text/css" />
</asp:ContentPlaceHolder>
This may be helpful for you - How to pass page’s meta tags in ASP.NET MVC?
If you don't want to override existing tags in the master, you can add a content placeholder inside the head tag too:
<head runat="server">
<title>
<asp:ContentPlaceHolder ID="title" runat="server">
Default Title</asp:ContentPlaceHolder>
</title>
<!-- The ContentPlaceHolder is placed inside the title tag to make sure that the
document validates in the VS editor - <title> needs to be a direct child of
<head>. The output will validate. -->
<script src="theAllFamous_jQuery.js" type="text/javascript" />
<link href="sitewide.css" type="text/css" rel="Stylesheet" />
<asp:ContentPlaceHolder ID="headContent" runat="server />
</head>
And in your view:
<asp:Content ID="title" ContendPlaceHolderId="title" runat="server">
Page specific title
</asp:Content>
<asp:Content ID="head" ContentPlaceHolderId="headContent" runat="server">
<link href="pagespecific.css" type="text/css/ rel="Stylesheet" />
</asp:Content>
That way you won't have to duplicate code that you want in all head tags on your site.