How can I change my metatag in my masterpage?

N

needin4mation

Hi, I have a metatag description like

(this is in my masterpage)
<meta name="description" id="MyMETADesc"....

but this *inline* code fails:

(this is in a contentpage based upon the master)

<script runat=server>
protected void Page_Load(object sender, EventArgs e)
{
MyMETADesc.Attributes("content")="Test";
}
</script>

I get can't find MyMETADesc.

This is all inline with master and content, and I don't know how to
reference the metatag's ID. Can anyone help? Thank you.
 
B

Bruno Alexandre

to easy :)

in your Master.Page your <head> tag must be folowed by runat="server" like:
<head runat="server">
<title>my Own Website</title>
<link rel="stylesheet" type="text/css" href="../includes/css/general.css"
/>
</head>

in your Content page just add the follow code:
----------------------------------------------------------------------------------
in VB.NET
----------------------------------------------------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' Get the htmlHead your aspx page is using (from the Master page)
' Master page must include the runat server attribute in the head tag:
<head runat="server">
Dim head As HtmlHead = CType(Header, System.Web.UI.HtmlControls.HtmlHead)

' Create a htmlMeta object
Dim meta As HtmlMeta = New HtmlMeta()

' Specify meta attributes
meta.Attributes.Add("name", "keywords")
meta.Attributes.Add("content", "keyword1, keyword2, keyword3")

' Add the meta object to the htmlhead's control collection
head.Controls.Add(meta)
End Sub
----------------------------------------------------------------------------------
in C#
----------------------------------------------------------------------------------
//Get the htmlHead your aspx page is using (from the Master page)
//Master page must include the runat server attribute in the head tag: <head
runat="server">
HtmlHead head = (System.Web.UI.HtmlControls.HtmlHead)Header;

//Create a htmlMeta object
HtmlMeta meta = new HtmlMeta();

//Specify meta attributes
meta.Attributes.Add("name", "keywords");
meta.Attributes.Add("content", "keyword1, keyword2, keyword3");

// Add the meta object to the htmlhead's control collection
head.Controls.Add(meta);


Note that this code is only valid for version 2.0 of the Framework.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top