473,672 Members | 2,957 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.P age, and adds a new Property called
"MetaKeywor ds" or whatever.

I've created a class called BasePage (in the App_Code folder), which
inherits from System.Web.UI.P age, 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.P age 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 2940
Found it. I was missing the @Page's CodeFileBaseCla ss element.

However, Visual Studio still doesn't recognise my "MetaKeywor ds" 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.P age, and adds a new Property called
"MetaKeywor ds" or whatever.

I've created a class called BasePage (in the App_Code folder), which
inherits from System.Web.UI.P age, 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.P age 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.micr osoft.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*******@comm unity.nospamwro te in message
news:B2******** *************** ***********@mic rosoft.com...
Found it. I was missing the @Page's CodeFileBaseCla ss element.

However, Visual Studio still doesn't recognise my "MetaKeywor ds" 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.P age, and adds a new Property called
"MetaKeyword s" or whatever.

I've created a class called BasePage (in the App_Code folder), which
inherits from System.Web.UI.P age, 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.P age 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.M asterPage
{
protected void Page_Load(objec t sender, EventArgs e)
{
HtmlMeta meta1 = new HtmlMeta();
meta1.Name = "keywords";
meta1.Content = "keywords from master page";
Page.Header.Con trols.Add(meta1 );

}
}

=======code in content page=========== ===
public partial class ContentPage1 : System.Web.UI.P age
{
protected void Page_Load(objec t 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
1677
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 get the following error: "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)."
2
1191
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, maybe even for that little site linked to above. Either way, I would like to find out more about my options. I know that Whidby has this great new MasterPage solution....but that doesn't help me right now. What are most of you using? Are...
6
1759
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 the content pages. Can this be done and if so how. I have made the Varibles that I wish to access Public Members. Thanks for any help. Kenneth
4
1519
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 loads. In ASP.NET 2.0 can I do the same thing by calling the class on the MasterPage's code-behind before it's Page_Load and will this run before the content page's Page_Load? -- Jeff Lynch
2
2459
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 and want to be able to populate the ContentPlaceholders of the inner-most masterpage at run-time.
5
4310
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 the best choise? 1) Using Masterpages with Themes (css / images / skins included in this theme)
3
4311
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 done using the code below. When I add masterpages to Album.aspx and remove all the html tags I get the error System.NullReferenceException: Object reference not set to an instance of an object. for the highlighted yellow line below. I notice once I...
0
1432
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 control which is placed on every page. Originally, the reason why I chose to do it this way (instead of placing the header in a master page) is because my header tabs change dynamically based on who the user is. My question is, am I losing...
0
2255
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 file of map of the site, the web.config and another page to do tests.
0
8498
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8418
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8628
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6249
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4237
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4433
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2830
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2083
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1831
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.