MasterPages and a Base class

G

Guest

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
 
G

Guest

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!?
 
C

clintonG

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=-88043838&z=17&l=0&m=h
 
S

Steven Cheng[MSFT]

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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.

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



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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top