Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > How to change meta descritption from a web part? View modes: 
User avatar
Member
Member
Real Salmon - 5/10/2011 4:22:35 PM
   
How to change meta descritption from a web part?
Hi -

I have a web part that I've inherited that gets and displays content from a web service. As part of this, the page title is updated with a simple bit of text replacement. . .

// Replace the token "{report-title}" that is in the "Page title" field from Metadata
this.Page.Title = this.Page.Title.Replace("{report-title}", "New title from web service");


This part works great.

I would like to do the same thing with the meta description, but this does not appear to work in the same manner. For simplicity's sake, this is what I have tried . . .

this.Page.MetaDescription = "New Description";




The MetaDescription property is something that IntelliSense pops out in VS, so it seemed a likely solution. However, the meta description in the <head> section of the resulting page remains unchanged.

What's the best way to go about this?

Thanks for any help.

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 5/12/2011 6:58:42 AM
   
RE:How to change meta descritption from a web part?
Hi,


if you leave the decription in document Properties -> Metadata blank, you can use code like this:

this.Page.Header.Controls.Add(new LiteralControl("<meta name=\"description\" content=\"aaaa\" />"));

It will add the description to the header. In this case, the description is "aaaa".


Best regards,
Helena Grulichova

User avatar
Member
Member
Real Salmon - 5/12/2011 10:15:35 AM
   
RE:How to change meta descritption from a web part?
kentico_helenag wrote: if you leave the decription in document Properties -> Metadata blank, you can use code like this:

this.Page.Header.Controls.Add(new LiteralControl("<meta name=\"description\" content=\"aaaa\" />"));

It will add the description to the header. In this case, the description is "aaaa".


That seems to have done the trick. Many thanks!