page document mode - asp.net

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);

Related

ASP.NET ContentPage with Form Controls

I created a content page that references a master page. In the content page I have a form and some form controls with a submit button. When I hit submit though the parameters are not detected on page load in the content page. On top of that the name of the parameters are all messed up.
What is the correct way of adding form controls to the content page and then using Request.QueryString[ID]?
I just realized that Microsoft throws all kinds of extra crap at you when you use master pages. It is absolutely ridiculous, is there a way for me not to go down this route of using all kinds of silly casting and inefficient overhead:
http://www.asp.net/web-forms/tutorials/master-pages/control-id-naming-in-content-pages-cs
My code (MASTER PAGE):
<%# Master Language="C#" AutoEventWireup="true" ClientIDMode="Static" %>
<!DOCTYPE html>
<html lang="en">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="Head" runat="server"></asp:ContentPlaceHolder>
</head>
<body>
<asp:ContentPlaceHolder runat="server" ID="MainContent" />
</body>
</html>
My code (Content Page):
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<label for="iSiteId">Site Id(s)</label>
<asp:TextBox ID="iSiteId" runat="server"></asp:TextBox>
<label for="iVersion">Version(s)</label>
<asp:TextBox ID="iVersion" runat="server"></asp:TextBox>
</asp:Content>
My Code (Content Page but the Code behind)
_siteId = Request.QueryString["iSiteId"];
_categoryId = Request.QueryString["iCategoryId"];
_version = Request.QueryString["iVersion"];
Try these instead:
siteId = iSiteId.Text;
_categoryId = iCategoryId.Text;
_version = iVersion.Text;

adding css class in content pages

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>

Contentplace holder

Can we use Content place holder within the head section of a master page?
for example :
<head runat="server">
<title>Untitled Page</title>
<asp:ContentPlaceHolder id="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
The short answer is yes. Is it not working for you?
You can use ContentPlaceHolder within the head section of a master page. I'm sending you a working example, out of my project. Make sure you set the attribute runat="server" for head tag. You can also have multiple ContentPlaceHolders within the head tag. see example and enjoy :)
<head ID="Head1" runat="server" Visible="true">
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<!--PageTitle_START-->
<title>
<asp:ContentPlaceHolder ID="PlaceHolderPageTitle" runat="server></asp:ContentPlaceHolder>
</title>
<!--PageTitle_END-->
<asp:ContentPlaceHolder ID="PlaceHolderHeaderScripts" runat="server"></asp:ContentPlaceHolder>
</head>
As long as the <head> tag has a runat=”server” attribute defined, a content page can programmatically add to the <head> section of an ASPX page. The following is perfectly valid:
<head runat="server">
<asp:ContentPlaceHolder runat="server" id="headerPlaceHolder" />
</head>

Links css file to a content page

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

Include CSS file in view

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.

Resources