In My example I am writing Meta contents of my page from a utility class file.
Lets say my following method is in utility.cs file
// method that will write meta tags for keyword and description.
public static void WriteMetaTags(Control ctrl, string keyword, string desc)
{
Page pge = (Page)ctrl;
HtmlMeta mKey = new HtmlMeta();
mKey.Name = "keyword";
mKey.Content = key;
pge.Header.Controls.Add(mKey);
HtmlMeta mDesc = new HtmlMeta();
mDesc.Name = "description";
mDesc.Content = desc;
pge.Header.Controls.Add(mDesc);
}
I need to call this method from my .aspx page like this.
utility.WriteMetaTags(this, keyword, desc) and its done.
You can also call this method from a user control like
utility.WriteMetaTags(this.parent, keyword, desc)
Enjoy!!!
If you like this article, subscribe to our
RSS Feed. You can also
subscribe via email to our Interview Questions, Codes and Forums section.