动态隐藏/显示元标记ASP.NET

时间:2013-04-02 16:50:02

标签: asp.net metadata

嘿所以目前我正在放置meta标签,例如:

<meta name="WT.oss_r" content="<%= SearchNumberOfResults%>"/>

我正考虑将其放在ASP:Panel中,并设置为truefalse可见,具体取决于SearchNumberOfResults String.IsNullOrEmpty,但这会使div标记为在<head>部分,这是不理想的..

隐藏和显示元标记的好方法是什么?

2 个答案:

答案 0 :(得分:1)

private string description;

页面初始化:

HtmlMeta tag = new HtmlMeta();
tag.Name = "description";
tag.Content = description;
Header.Controls.Add(tag);

请参阅:Using-Meta-Tags-with-Master-Pages-in-ASP-NET


<%@ Page Language="C#" MetaKeywords="<%=SearchNumberOfResults%>" MetaDescription="This is my blog that focuses on ASP.NET." AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

protected void Page_Load(object sender, EventArgs e)
{                        
    Page.MetaDescription = "sample meta description";
}

答案 1 :(得分:0)

添加元标记:

runat="server" id="xxx"

并在ASP.NET代码中

MyPanel.xxx.visible = false;

OR

xxx.visible = false;

我相信“面板”不适用于头部