468,784 Members | 1,553 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,784 developers. It's quick & easy.

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 2716
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by neverstill | last post: by
6 posts views Thread by Kenneth Keeley | last post: by
4 posts views Thread by Jeff Lynch | last post: by
2 posts views Thread by iturner100 | last post: by
reply views Thread by Sergio E. | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.