Solved

Setting HtmlMeta from outside class

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Initial get page response times and IIS8 15 55
ASP.NET(C#) Eliminating weekends from a date range 2 45
asp.net mvc5 6 20
MailAddress in vb 4 29
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…

809 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