如何根據主頁面和內容頁面(動態)爲項目中的內容頁面添加標題和元標記?如何在基於主內容頁面(動態)的項目中爲內容頁面添加標題和元標記
我用下面的方法對母版頁:
public void SetMetaTags(string title, string description, string keywords)
{
// Get a reference to the HTML Head
HtmlHead headTag = (HtmlHead)Page.Header;
// Set the page title
headTag.Title = title;
// Add a Description meta tag
HtmlMeta metaTag = new HtmlMeta();
metaTag.Name = "Description";
metaTag.Content = description;
headTag.Controls.Add(metaTag);
// Add a Keywords meta tag
metaTag = new HtmlMeta();
metaTag.Name = "Keywords";
metaTag.Content = keywords;
headTag.Controls.Add(metaTag);
}
,所以我不知道爲什麼在內容頁Page_Load
下面的代碼中有一個錯誤:
protected void Page_Load(object sender, EventArgs e)
{
MasterPage MyMasterPage = (MasterPage)Master;
// Error on this line:
MyMasterPage.SetMetaTags("Title", "description", "keywords");
}
和誤差:
Error 17 'System.Web.UI.MasterPage' does not contain a definition for
'SetMetaTags' and no extension method 'SetMetaTags' accepting a first argument of
type 'System.Web.UI.MasterPage' could be found (are you missing a using directive
or an assembly reference?)
C:\Javad\---\AlmasAfzar\AlmasAfzar\AlmasAfzar\Products.aspx.cs 16 26
AlmasAfzar
感謝未來的提前
最好的問候
您所看到的錯誤是什麼? (並在哪一行?) – 2010-10-17 17:48:34