Head Data in linked master/Content Page (Full Version)

All Forums >> [Web Development] >> Expression Web Help



Message


Avick -> Head Data in linked master/Content Page (12/2/2007 11:39:04)

I’m having a bit of a problem with the head section of a Master page and a Content Page.

I am trying to add different CSS Page and some head tags to each content page linked to a master page.

I have searched the web and found a little information on the topic but no one makes it clear where the code should go and how it should be formatted.

If I can achieve this then I would be able to add Keywords and Descriptions to each page along with a different style sheet.
I can put the page title in, no problem, but I would like to access more then this on each page.

Anyone any Ideas.




Tailslide -> RE: Head Data in linked master/Content Page (12/2/2007 14:52:44)

Why would you want a different stylesheet on different pages? Much too much like hard work - best to keep them to a minimum (maybe a normal one, a PDA one and a print one plus maybe an IE one if necessary). You could give each page an id in it's body element and then specify different rules in the normal stylesheet according to that body id - so effectively giving a page a whole different look if required.

Are you talking about a template or something like that - as you can easily add different content to your head area in a normal static site.

If you use PHP you can also specify content according to which page you're on (you give each page an id and then add a script saying something like - if this is "home" then do this, otherwise do that).




Avick -> RE: Head Data in linked master/Content Page (12/2/2007 17:20:29)

Hi Tailslide
I am planning to have a separate Style Sheet for each section of the site so I can change the color of each section.

I create one master Style Sheet then using the @import item I can create different style sheets with just a very few lines of code.

As for the other items.
I want to put a different list of Meta tags on each page such as creation date, descriptions and so on.
I have left PHP behind as most if not all my work involves ASPX, MS SQL and Access.

I believe it can be done, I just don’t know how!! I don’t really want to go back to Creating a template and generating my pages from that as the master page is so much better.




rdouglass -> RE: Head Data in linked master/Content Page (12/12/2007 15:20:45)

Does my answer to this post help you here at all?

http://www.frontpagewebmaster.com/m-378831/tm.htm

Except what you'd add is something like this for your CSS:

Dim cssLink As New HtmlLink()
cssLink.Href = "styles.css"
cssLink.Attributes.Add("rel", "Stylesheet")
cssLink.Attributes.Add("type", "text/css")
Me.Header.Controls.Add(cssLink)

Hope it helps.




Avick -> RE: Head Data in linked master/Content Page (12/13/2007 6:29:21)

Hi Rdouglass
That is what I am looking for.

Where do I put this code and in what tags. Can you give me an example??




rdouglass -> RE: Head Data in linked master/Content Page (12/13/2007 8:37:22)

Did you see my reference to the other post? That has a VB.NET example there for a code-behind page. It would look somethinkg like this:

Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Partial Class MyPageClass
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim cssLink As New HtmlLink() 
        cssLink.Href = "styles.css" 
        cssLink.Attributes.Add("rel", "Stylesheet") 
        cssLink.Attributes.Add("type", "text/css") 
        Me.Header.Controls.Add(cssLink) 

    End Sub
End Class


You don't put this in any tags but rather this creates the tags and code for a reference to your CSS. This would be on the code-behind page. If your page was named myPage.aspx, the code-behind page would be myPage.aspx.vb and you'd put that code in there.

Hope it helps.




Avick -> RE: Head Data in linked master/Content Page (12/13/2007 9:36:17)

I have read your other post and I just don't get it. Call me tick but it makes no sense.

I give up. Its not for me.
No matter what I do I can't get it to work. I have read as much as I can about it and still can't get it right.

Its just far to much effort for to little reward.




rdouglass -> RE: Head Data in linked master/Content Page (12/14/2007 0:31:13)

quote:

I give up. Its not for me.


That's too bad.[8|] Master pages are great but if you don't take advantage of some of the 'fun' things about the .NET environment, you're missing a significant part of it IMO. Customized CSS with Master pages is a great tool for multi-user environments. I'm doing it myself in a few projects.

If you're at all interested in attempting it again, I put together a very simple setup of a master page and a test page (both with associated .vb files) and 2 simple CSS pages. Very simple pages indeed but show the concept quite clearly IMO. The trick is all in the TestPage.aspx.vp page. You'll see where I used a SELECT statement to specify which stylesheet I want to use.

Here's a ZIP of those files if you want them:

http://www.rogerdouglass.com/css_test.zip

Hope it helps.




Avick -> RE: Head Data in linked master/Content Page (12/14/2007 4:39:21)

OK ,
I have downloaded the file and I will give it another go. Fingers crossed that little spark lights in my brain :)




Avick -> RE: Head Data in linked master/Content Page (12/14/2007 9:20:15)

It worked [:D] [:D]

I think I am starting to understand it now.
Have to play around with it a bit more to make sure I have it right.

How would I put multiple items in a header tag such as description, keywords, creation date and css links.




rdouglass -> RE: Head Data in linked master/Content Page (12/14/2007 10:02:30)

These are the ones I am currently familiar with.

'Adding Title:
Me.Header.Title = "Title Of Page Here"

'Add Meta description:
Dim metaDescription As New HtmlMeta()
metaDescription.Name = "description"
metaDescription.Content = "A description of the page here."
Me.Header.Controls.Add(metaDescription)

'Add Meta keywords:
Dim metaKeywords As New HtmlMeta()
metaKeywords.Name = "keywords"
metaKeywords.Content = "keyword1, keyword2"
Me.Header.Controls.Add(metaKeywords)

Add a head style :
Dim styles As New HtmlGenericControl("style")
styles.Attributes.Add("type", "text/css")
styles.InnerText = "p { font-weight: bold; }"
Me.Header.Controls.Add(styles)

'Add style sheet:
Dim cssLink As New HtmlLink()
cssLink.Href = "styles.css"
cssLink.Attributes.Add("rel", "Stylesheet")
cssLink.Attributes.Add("type", "text/css")
Me.Header.Controls.Add(cssLink)

'Add a Java Script:
Dim javaScript As New HtmlGenericControl("script")
javaScript.Attributes.Add("type", "text/javascript")
javaScript.InnerText = "alert('Hello World!');"
Me.Header.Controls.Add(javaScript)


All the above code should be used within page Page_Load event and you can use all the standard ASP.NET stuff (like the SELECT CASE I used) to determine what the actual content will be for each.

Hope it helps.

EDIT: Typo's [:'(]




Avick -> RE: Head Data in linked master/Content Page (12/14/2007 11:23:36)

Fantastic :) :)
Why was I not using these before. :)

rdouglass you have converted me. I have since created the following code for a number of pages and its out of this world.

Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Partial Class design
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

		Dim metaDescription As New HtmlMeta()
		metaDescription.Name = "description"
		metaDescription.Content = "Website design by Neweb Ireland. Discover the better way to design."
		Me.Header.Controls.Add(metaDescription) 
		
		Dim metaKeywords As New HtmlMeta()
		metaKeywords.Name = "keywords"
		metaKeywords.Content = "Neweb, Ireland, Design, Dublin"
		Me.Header.Controls.Add(metaKeywords) 	
	End Sub  

End Class

Partial Class templates
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

		Dim metaDescription As New HtmlMeta()
		metaDescription.Name = "description"
		metaDescription.Content = "Standard Templates for your website."
		Me.Header.Controls.Add(metaDescription) 
		
		Dim metaKeywords As New HtmlMeta()
		metaKeywords.Name = "keywords"
		metaKeywords.Content = "Neweb, Ireland, Design, Dublin, web templates"
		Me.Header.Controls.Add(metaKeywords) 	
	End Sub  

End Class


This makes life so much better.
What a difference a day makes [:D]




rdouglass -> RE: Head Data in linked master/Content Page (12/14/2007 12:21:24)

quote:

you have converted me


Don't blame me for that. [:D]

quote:

What a difference a day makes


And you almost gave up. [;)] Glad I could help.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.078125