Solved

Setting HtmlMeta from outside class

Posted on 2009-04-09
3
298 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
  • 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now