FiveTools
FiveTools

Reputation: 6030

Add an attribute to the <HTML> element in asp.net?

I would like to add two additional xml namespaces to the <HTML> element in asp.net:

take:

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

to make (adding facebook open graph namespaces):

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:og="http://ogp.me/ns#"
      xmlns:fb="http://www.facebook.com/2008/fbml">

How would I access the <HTML> element in code behind and add a namespace?

Upvotes: 4

Views: 12979

Answers (3)

Mr.B
Mr.B

Reputation: 3787

I hope it is helpful. How to set "enabled/disabled" for a button:

  <button type="button" class="btn btn-primary btn-md remove-button" <%=GetDisabledGtmlAttribute(IsUIDisabled) %>>>Remove</button>

C#:

  protected string GetDisabledGtmlAttribute(bool isUIDisabled)
    {
        if (isUIDisabled)
        {
            return "disabled";
        }
        return string.Empty;
    }

Upvotes: 0

brendan
brendan

Reputation: 29986

You can do it just like any other element. In your aspx just mark the html tag to be runat server:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" id="html_tag" runat="server">

And in your code just add the attributes:

protected void Page_Load(object sender, EventArgs e)
{
   html_tag.Attributes.Add("xmlns:og","http://ogp.me/ns#");
   html_tag.Attributes.Add("xmlns:fb", "http://www.facebook.com/2008/fbmls");
}

This of course does not have to be done via code and can just be placed in your aspx unless you wanted to only include those attributes in certain conditions.

Upvotes: 12

Ankur
Ankur

Reputation: 33637

You can do something like as below:

<html <%= GetTags() %> >

The GetTags function will be defined in your code behind file and should return a string which will be placed in html tag, so you can return the "tags" as string and it will appear in HTML tag.

But I am not getting your point of doing this from code behind. Why not just do it in the aspx itself?

Upvotes: 1

Related Questions