Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Inherit master page?

Reply
Thread Tools

Inherit master page?

 
 
=?Utf-8?B?TWF0dA==?=
Guest
Posts: n/a
 
      07-03-2007
1. I have a master page. Is it possible to create another master page inherit
the existed one?

2. Is it possible to inject css link, js script block to the head part of
web content page?
 
Reply With Quote
 
 
 
 
Cowboy \(Gregory A. Beamer\)
Guest
Posts: n/a
 
      07-03-2007

"Matt" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 1. I have a master page. Is it possible to create another master page
> inherit
> the existed one?


How much do you love design view? Technically, it is possible, but it does
not render right now.

> 2. Is it possible to inject css link, js script block to the head part of
> web content page?


If you have a content area in the head, you can attach js, etc. to it. You
can also inject into the master header.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)

************************************************
Think outside the box!
************************************************


 
Reply With Quote
 
 
 
 
David R. Longnecker
Guest
Posts: n/a
 
      07-03-2007
> 1. I have a master page. Is it possible to create another master page
> inherit the existed one?


Using Visual Studio 2005 and ASP.NET 2.0? Not "really". You'll lose the
designer view, but if you're fine with dealing with the code, there's a way.

If you create both of your master pages and then, in an inherited "defaultPage",
you can code it up to pass the master page as a parameter.

private string runtimeMasterPageFile;

public string RuntimeMasterPageFile
{
get { return runtimeMasterPageFile; }
set { runtimeMasterPageFile = value; }
}

protected override void OnPreInit(EventArgs e)
{
if (runtimeMasterPageFile != null)
{
MasterPageFile = runtimeMasterPageFile;
}

base.OnPreInit(e);
}

So, on the page that would inherit both, your Page tag would look like below.
In this example, I have a Default.master page, but also a Secondar.master
page.

<%@ Page Language="C#" CodeFileBaseClass="DefaultPage" MasterPageFile="~/Default.master"
RuntimeMasterPageFile="~/Secondary.master"
AutoEventWireup="true" CodeFile="ViewStudent.aspx.cs"
Inherits="ViewStudent" Title="Untitled Page" Async="true" %>

The code for this was snatched up from Scott Guthrie's blog at http://weblogs.asp.net/scottgu/archi...11/430382.aspx
and has worked great over the past couple of years.

Now, if you're looking forward or experimenting with the new Visual Studio
2008 and .NET 3.0/3.5, MasterPages CAN use other MasterPages. The Page tag
is rendered as below. When you create a new master page, it has the option,
just like any other page, to select a master page.

<%@ Master Language="C#" MasterPageFile="~/ParentMasterPage.master" AutoEventWireup="false"
CodeFile="ChildMasterPage.master.cs" Inherits="ChildMasterPage" %>

> 2. Is it possible to inject css link, js script block to the head part
> of web content page?


Explore the Page.Header object and it's attributes. For example, for your
CSS link:

HtmlLink customStyleSheet = new HtmlLink();
customStyleSheet.Href = "StyleSheet.css";
customStyleSheet.Attributes.Add("type", "text/css");
customStyleSheet.Attributes.Add("rel", "stylesheet");
Page.Header.Controls.Add(customStyleSheet);


If nothing else, you can add a <div> with an id and runat=server attribute
and drop controls, or CSS in, with literal controls.

<head runat="server">
<div id="MyCustomContent" runat="server" />
</head>

Then, in code behind:

protected void Page_Load(object sender, EventArgs e)
{
MyCustomContent.InnerHtml = @"<link href='StyleSheet.css' rel='stylesheet'
type='text/css' />";
}

You could do the same with a <script> tag, I'm assuming..

HTH.

-dl

--
David R. Longnecker
http://blog.tiredstudent.com

> 1. I have a master page. Is it possible to create another master page
> inherit the existed one?
>
> 2. Is it possible to inject css link, js script block to the head part
> of web content page?
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Access Master Page Controls from page.aspx doesn't inherit from master SerpentKiss2010 ASP .Net 0 04-06-2011 02:46 PM
need to lookup master interface that inherit IP address to unnumbered interface via SNMP tua Cisco 0 10-30-2007 12:30 PM
Cross Page Post Back When Using Mixture of Master Pages and Non-Master Pages Jason@webbit.com ASP .Net 1 05-16-2006 02:00 PM
Master Pages Great! But what about Master User Controls? Electrified Research ASP .Net 5 10-11-2005 02:32 PM
seeking servlet "Master" keep getting "Master/servlet/Master" not found. Tomcat 5.0.25 Doug McCann Java 1 08-05-2004 09:16 PM



Advertisments