Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 30th, 2006, 11:46 AM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default MasterPages ContentPages and Meta tags


I saw a post
http://p2p.wrox.com/topic.asp?TOPIC_ID=34053 and wondered if anyone could help me regarding placing meta tags within content pages.

There's a couple of questions I've placed below within the instructions given.



1. In your Master page, add the following tag to the <head> of the page:
  <meta name="keywords" content="" id="MyMetaTag" runat="server" />
2. In the code behind of the Master page, add the following property:
  Public Property MetaData() As String
    Get
      Return MyMetaTag.Content
    End Get
    Set(ByVal value As String)
      MyMetaTag.Content = value
    End Set
  End Property

Question do I have to import anything, and does this have to be placed in the page_load event?

3. In your Content page get a strongly typed version of your master and set the MetaData property like this:
    Dim myMaster As MainMaster = CType(Me.Master, MainMaster)
    myMaster.MetaData = "Hello World"

Where do I place this code in my content page?


thanks.
Michael.

Reply With Quote
  #2 (permalink)  
Old May 30th, 2006, 03:33 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Michael,

No, you don't need to add an Imports system.

First, add the meta tag as described in my post. Make sure it's placed inside the <head> section that has a runat="server" attribute as well.

Then add the MetaData as a property to the page. You should end up with something like this:
Code:
Partial Class MainMaster 
  Inherits System.Web.UI.MasterPage

  ' Other stuff, like Page_Load etc can go here

  Public Property MetaData() As String
    Get
      Return MyMetaTag.Content
    End Get
    Set(ByVal value As String)
      MyMetaTag.Content = value
    End Set
  End Property

End Class
This gives your master page a property that you can access from other pages.

Then in your content page, set the MetaData property in any place that makes sense. Most likely, this is inside the Page_Load event, like this:
Code:
Protected Sub Page_Load(ByVal sender As Object, _
       ByVal e As System.EventArgs) Handles Me.Load
  Dim myMaster As MainMaster = CType(Me.Master, MainMaster)
  myMaster.MetaData = "Hello World"
End Sub
Instead of in Page_Load, you can use the exact same code in a custom method (or any other event) that you have in your page.

Does this help?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Reply With Quote
  #3 (permalink)  
Old May 31st, 2006, 12:42 AM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,
When I place the code below in my masterpage 'masterpage.master.vb' (I'm using VWD) I get a blue squigley line underneath MyMetaTag. When I hover over it I get the tooltip - Name 'MyMetaTag' is not declared.
any ideas what's wrong?



here's the code for 'masterpage.master.vb'

Partial Class masterpage
    Inherits System.Web.UI.MasterPage

    ' Other stuff, like Page_Load etc can go here

    Public Property MetaData() As String
        Get
            Return MyMetaTag.Content
        End Get
        Set(ByVal value As String)
            MyMetaTag.Content = value
        End Set
    End Property

End Class


Here's part of the MasterPage 'MasterPage.master'

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>Untitled Page</title>
<meta name="keywords" content="" id="MyMetaTag" runat="server" />
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>


And here's the testmonials codebehind file code

Partial Class testimonials
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, _
           ByVal e As System.EventArgs) Handles Me.Load
        Dim myMaster As MasterPage = CType(Me.Master, MasterPage)
        myMaster.MetaData = "Hello World"
    End Sub


End Class

thanks,
Michael.

Reply With Quote
  #4 (permalink)  
Old May 31st, 2006, 01:39 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

That's weird, and now it's supposed to be. I successfully implemented the meta stuff with the steps I described.

Can you post the code for the master page and its code behind?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: The Story Ends by Clan of Xymox (Track 13 from the album: Hidden Faces) What's This?
Reply With Quote
  #5 (permalink)  
Old May 31st, 2006, 02:36 PM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar thank you for all your help it's been greatly appreciated.

The problem was my master page had the directives

<%@ Master Language="VB" %>

and should have been

<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage"

thanks,
Michael.


Reply With Quote
  #6 (permalink)  
Old June 1st, 2006, 04:13 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You're welcome. Glad it's working now...

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: Half the Man by Hed Planet Earth (Track 7 from the album: Blackout ) What's This?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using meta tags amatytfc ASP.NET 2.0 Basics 1 August 6th, 2007 05:47 PM
meta tags ferlach HTML Code Clinic 5 June 5th, 2007 04:17 PM
META tags and master pages thenoseknows ASP.NET 2.0 Professional 1 October 9th, 2006 01:02 PM
Meta tags Adam H-W HTML Code Clinic 2 November 19th, 2003 11:25 AM
Database Driven Website w/ META tags Dan Jallits PHP How-To 2 June 16th, 2003 11:42 AM



All times are GMT -4. The time now is 12:01 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.