Showing posts with label keywords. Show all posts
Showing posts with label keywords. Show all posts

Thursday, March 22, 2012

Set Meta Data from Code Behind

Can one set the page's Description and Keywords from the Code Behind?
I got a page that will display a company's information.
Depending on what company are loaded, I want to build the Keywords and Description MetaData dynamicallyASP.NET 1.1 or 2.0?
Oh, I think you use 1.1...

OK, you have your meta tags, as usual on your page. Add two attributes to it. An ID, and a runat="server" attribute. So you end up with something like

<meta name="keywords" content="default keywords" id="MetaKeywords1" runat="server"/>

Then in your codebehind, you should see MetaKeywords1 declared as an HtmlGenericControl control. If not, you should add it there because Visual Studio sometimes misses out on these things.

THEN, in the Page Load event,

MetaKeywords1.Attributes["content"] = "blah,blah2,blah3";
oooooh (stupid sounding ooooh)...easy like that.

Just been wondering...is it worth even setting the meta data for pages that are loaded in iFrames?

I mean, from the bit I read using meta data for search engine optimization are hardly worth it these days.

Thanks anyhow M. This thing say I give you too many reputations, and must spread the love first. Better stop that before I get redirected to gay sites or something.
(Thank you, thank you)

Yes, setting metadata is still helpful, especially when it comes to Google, the most important search engine out there. In fact, there are even SEO techniques out there that one ought to keep in mind. For example, in your <head> section, you ought to have the title first, and then description and then keywords and then any other meta tags you may have. And google does care about the meta keywords and description, so it's always worth setting it.

Set Metadata in code-behind

Can one set your page meta data in your code behind?
For instance, this one page can display any of many companies.
I want to add a keywords, and description fiield in the database for a company.
When this page load, I want to set the page's metadata to what is in the database..so i have to do it in my code behind.

Currently, I do something like this:
<meta content="Nico Nel (Accuracy Automotive)" name="author">
<meta content="nico@dotnet.itags.org.accuracyauto.com" name="reply-to">
<% if (Language == "ja-JP") {%>
<meta content="Japanese Description." name="description">
<meta content="Japanese Keywords" name="keywords">
<LINK href="http://links.10026.com/?link=styles/style_ja.css" type="text/css" rel="stylesheet">
<%} else if (Language == "en-US") {%>
<meta content="English Description." name="description">
<meta content="English Keywords" name="keywords">
<LINK href="http://links.10026.com/?link=styles/style_en.css" type="text/css" rel="stylesheet">
<%} else {%>
<meta content="Chinese Description." name="description">
<meta content="Chinese Keywords" name="keywords">
<LINK href="http://links.10026.com/?link=styles/style_zh.css" type="text/css" rel="stylesheet">
<%}%>Set each of the <meta> tags to runat=server.
Give them an ID.

You can now access them from your codebehind.
Just like any control.
cool..thanks M.
Hmmm...as what do one declare them variables in your code?
(you know..like a table cell would be protected htlmtablecell mycell;)