473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

MasterPages and a Base class

Hi guys

I'm well into a project at the moment which uses a MasterPage. I'm also
using seperate code-behind files for each page (C#).

I just realised that the MasterPage doesn't give you a property to set Meta
Keywords. It's got Description and Title, but not Keywords.

Reading around on the web, I should be able to create a new class which
inherits from System.Web.UI.Page, and adds a new Property called
"MetaKeywords" or whatever.

I've created a class called BasePage (in the App_Code folder), which
inherits from System.Web.UI.Page, and now I've gone through all the pages .cs
files and changed their inheritance to "BasePage".

This compiles, but I still can't get to the public MetaKeywords property I
created. It doesn't come up in autocomplete in the @page directive, and gives
me a "Error parsing attribute. System.Web.UI.Page does not have a public
property named MetaKeywords".

The @page directives still contain the Inherits="" item, which refers to the
codebehind class (_Default, Contact Us, etc depending on the page). But all
the classes inherit from BasePage?!

If I change the Inherits= to "BasePage", it still says it can't find
MetaKeywords!

Please - what have I missed?!

Ta

Dan
Feb 14 '07 #1
3 2927
Found it. I was missing the @Page's CodeFileBaseClass element.

However, Visual Studio still doesn't recognise my "MetaKeywords" property
when I use it within @Page, so gives me the squggly underline.

Is there any way I can get VS to accept it!?

"musosdev" wrote:
Hi guys

I'm well into a project at the moment which uses a MasterPage. I'm also
using seperate code-behind files for each page (C#).

I just realised that the MasterPage doesn't give you a property to set Meta
Keywords. It's got Description and Title, but not Keywords.

Reading around on the web, I should be able to create a new class which
inherits from System.Web.UI.Page, and adds a new Property called
"MetaKeywords" or whatever.

I've created a class called BasePage (in the App_Code folder), which
inherits from System.Web.UI.Page, and now I've gone through all the pages .cs
files and changed their inheritance to "BasePage".

This compiles, but I still can't get to the public MetaKeywords property I
created. It doesn't come up in autocomplete in the @page directive, and gives
me a "Error parsing attribute. System.Web.UI.Page does not have a public
property named MetaKeywords".

The @page directives still contain the Inherits="" item, which refers to the
codebehind class (_Default, Contact Us, etc depending on the page). But all
the classes inherit from BasePage?!

If I change the Inherits= to "BasePage", it still says it can't find
MetaKeywords!

Please - what have I missed?!

Ta

Dan
Feb 14 '07 #2
There's new classes available, notably an HtmlMeta class.

// search term
HtmlMeta class site:msdn2.microsoft.com

Don't forget to check out the other new classes in this context that will be
linked in the sidebar menu when the msdn2 page loads.You'll be using the
Page_PreInit event in the base class for many of these types of tasks when
using MasterPages.

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP http://wikimapia.org/#y=43038073&x=-...8&z=17&l=0&m=h
"musosdev" <mu*******@community.nospamwrote in message
news:B2**********************************@microsof t.com...
Found it. I was missing the @Page's CodeFileBaseClass element.

However, Visual Studio still doesn't recognise my "MetaKeywords" property
when I use it within @Page, so gives me the squggly underline.

Is there any way I can get VS to accept it!?

"musosdev" wrote:
>Hi guys

I'm well into a project at the moment which uses a MasterPage. I'm also
using seperate code-behind files for each page (C#).

I just realised that the MasterPage doesn't give you a property to set
Meta
Keywords. It's got Description and Title, but not Keywords.

Reading around on the web, I should be able to create a new class which
inherits from System.Web.UI.Page, and adds a new Property called
"MetaKeywords" or whatever.

I've created a class called BasePage (in the App_Code folder), which
inherits from System.Web.UI.Page, and now I've gone through all the pages
.cs
files and changed their inheritance to "BasePage".

This compiles, but I still can't get to the public MetaKeywords property
I
created. It doesn't come up in autocomplete in the @page directive, and
gives
me a "Error parsing attribute. System.Web.UI.Page does not have a public
property named MetaKeywords".

The @page directives still contain the Inherits="" item, which refers to
the
codebehind class (_Default, Contact Us, etc depending on the page). But
all
the classes inherit from BasePage?!

If I change the Inherits= to "BasePage", it still says it can't find
MetaKeywords!

Please - what have I missed?!

Ta

Dan

Feb 14 '07 #3
Hello Dan,

As Clinton has suggested, the HtmlMeta control can help build meta element
through server control model. As for setting meta keywords in Master page,
do you mean you want to add some keywords into the page's meta section in
Master page code? If this is the case, I think you do not have to add an
additional base page class because both Master Page and Content Page can
correctly access the output page's Header collection and add or modify meta
or other elements in it. e.g.

======code in master page========
public partial class site : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
HtmlMeta meta1 = new HtmlMeta();
meta1.Name = "keywords";
meta1.Content = "keywords from master page";
Page.Header.Controls.Add(meta1);

}
}

=======code in content page==============
public partial class ContentPage1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HtmlMeta meta1 = new HtmlMeta();
meta1.Name = "keywords";
meta1.Content = "keywords from content page";
Header.Controls.Add(meta1);

}
}
======================================

Does this helps for your problem?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 15 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: suzy | last post by:
Hello, I have created a template for my website using the masterpages template technique. It's working fine, except when I try to print the value of a querystring parameter in my HTML code, I...
2
by: neverstill | last post by:
So a new project has inspired me to look into page Templating once again. My current approach of dynamically loading user controls (http://www.ntsdirect.com) seems "hacky" for a larger scale site,...
6
by: Kenneth Keeley | last post by:
Hi, I have a Masterpage that controls the basic layout of the pages displayed on a web site. The masterpage also uses some variables. I would like to be able to access some of these variables from...
4
by: Jeff Lynch | last post by:
I need to call a class on every web page in a site. In ASP.NET 1.1 I would call this class before the Page_Load event in each web page's code-behind file since it needs to run before the web page...
2
by: iturner100 | last post by:
Hi, I've been struggling with this one for a couple of hours without much joy. Basically, I've got a set of nested masterpages (3 as it happens). I'm dynamically generating a new page in code...
5
by: Nick Wouters | last post by:
Dear All In Classic ASP I used CSS for ALL layout. Now in ASP.NET version 2 I am testing out Masterpages as they come in very handy. It seems like it is replacing CSS for layout but what is...
3
by: j-in-uk | last post by:
I have 3 pages Site.master, Album.aspx and ContinentsMenu.ascx. Continents is a usercontrol placed in Albums. In Album.aspx.cs I need to access a property from the Continents usercontrol and is...
0
by: Swami | last post by:
I have 2 questions relating to website design in asp .net: 1. In a website that I am building I have everything as a user control. Even the header, which contains the navigation tabs is in a user...
0
by: Sergio E. | last post by:
Hello, I have a problem with masterpages and forms security. I made a new Web site, in which I have my page of login like of beginning, a master page with only a sitemappath object in it, the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.