Link to home
Start Free TrialLog in
Avatar of NevinsLtd
NevinsLtd

asked on

Setting HtmlMeta from outside class

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

Avatar of samtran0331
samtran0331
Flag of United States of America image

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"
ASKER CERTIFIED SOLUTION
Avatar of samtran0331
samtran0331
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NevinsLtd
NevinsLtd

ASKER

Thanks for the hints