views:

32

answers:

4

Hello. I have a masterpage and I wrote metatags in masterpage.master.cs. In the category page which is generated from the masterpage every category has their own metatags. When the user visits category.aspx I want to change the metatags. All metatags are dynamically created and they don't have an id or runat because I create them dynamically with a for loop (reading data from the db).

So I can't change title of the page and metatags. How can I do this?

+2  A: 

To change the title use:

this.Title

To change the metatag, put a placeholder in the head of the masterpage.

<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">  
</asp:ContentPlaceHolder> </head>

You can also place a literal in that placeholder then fill the "text" property of this literal server side with the meta values from the database

Ivo
+1 that is exactly his problem, he needs the child pages to control the metatags in the masterpage. Excellent answer.
Achilles
+1. I agree with Achilles, this is the way to go if you're not willing to just use a different Master Page.
David Stratton
+1  A: 

Change your program design. The first two choices that come to mind are:

  1. Don't generate the META tags in a loop from the DB
  2. Use a different master page for this one page. <-- better choice for simplicity sake.

I know this seems like a flippant answer, but really, why make things harder on yourself (and the poor maintenance programmer who will come along after you) than they have to be? Keep it simple.

David Stratton
+1 I was and still am at times a poor maintenance programmer...I cry before I go to sleep...
Achilles
I bet you've got just as many horror stories as I do about maintenance programming. :)
David Stratton
A: 

Thanks David. But if user want to add meta tags how can user do it? My db design like that and I have to create tags with for loop. Is it not good? http://img843.imageshack.us/img843/6940/metadb.png

Is there any other way to write these tags?

@lvo, thanks for answer. But this.Title is not working. I wrote it but nothing chage. Also I didn't put any literal or label in contentplaceholder which id's head. Because if I put literal or something and I write it meta tags there will be 2 description or keywords in the page. Which one is ok for seo? Is there any other way to remove all meta tags?

kad1r
A: 

I fix my problem. I was wroted metatags in masterpage.master.cs. So other pages which are generated by this masterpage they all take the metatags from main masterpage. We already can't change the tags. Maybe we can change but I couldn't find any code. I wrote my metatags in default.cs and other pages are normal right now. Thanks for replies.

kad1r