Solved

Setting HtmlMeta from outside class

Posted on 2009-04-09
3
303 Views
Last Modified: 2012-05-06
I want to dynamically set the page Meta Tags based on certain criteria .. I'm using the following function..

The code works fine if placed in the same page, however, since what I want to do has more to do, I thought I want to place this code in a separate class and call it when I need it .. the problem is getting is issue:


'MyClassName' does not contain a definition for 'Header' and no extension method 'Header' accepting a first argument .... etc..

any idea of how can I cast or pass the value..

Thank you

public void setMeta(string tagName, string tagContent)
    {
 
        HtmlMeta meta_desc = new HtmlMeta();
        meta_desc.HttpEquiv = tagName;
        meta_desc.Content = tagContent;
        this.Header.Controls.Add(meta_desc);
 
    }

Open in new window

0
Comment
Question by:NevinsLtd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 37

Expert Comment

by:samtran0331
ID: 24111613
your "MyClassName" class has to inherit from System.Web.UI.Page
and then your pages should inherit from MyClassName

the technique is called "base pages"
0
 
LVL 37

Accepted Solution

by:
samtran0331 earned 500 total points
ID: 24111636
example:
http://www.4guysfromrolla.com/articles/041305-1.aspx

you can also google "asp.net base page" for tons more...ultimately...it lets your aspx pages have one place for shared code
0
 

Author Closing Comment

by:NevinsLtd
ID: 31568755
Thanks for the hints
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

634 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question