Question

I have a tag <html> in master page

<html xmlns="http://www.w3.org/1999/xhtml">

from another page that uses this master page I want to add one more attribute, finally I want to generate something like this:

<html xmlns="http://www.w3.org/1999/xhtml" 
          prefix="ya: http://webmaster.yandex.ru/vocabularies/">

Does anyone know how this can be accomplished ?

Was it helpful?

Solution

In your master set the tag to runat=server and give it an id like this:

<html lang="en" runat="server" id="masterHead">

In your masterpage .cs add this to set the property:

 public string SetPrefix
 {
    set { masterHead.Attributes.Add("prefix", value); }
 }

Then from your content page you can set it like this:

var master = Master as SiteMaster;

if (master != null)
((SiteMaster)Master).SetPrefix = "ya: http://webmaster.yandex.ru/vocabularies/";

In the above SiteMaster is your MasterPage, you may have to change it to the actual name of your MasterPage.

Demo image

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top