日期:2014-05-17  浏览次数:20497 次

meta 标签内 value 值不让使用 后台方法调用?
页面代码:

C# code

    public static string KeyWords = "关键字搜索1";
    public static string GetKeywords()
    {
        return "关键字搜索2";
    }


C# code

    

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    <meta name="Keywords" content="<%=Common.KeyWords %>" />
    <meta name="Keywords" content="<%=Common.GetKeywords() %>"/>
    <%=Common.GetKeywords() %>
</head>
<body>
    <form id="form1" runat="server">
    <div>

     <input type=text value="<%=Common.GetKeywords() %>" />
    </div>
    </form>
</body>
</html>



生成页面源代码:
HTML code

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
    无标题页
</title>
<meta name="Keywords" content="&lt;%=Common.KeyWords %>" />
<meta name="Keywords" content="&lt;%=Common.GetKeywords() %>" />
关键字搜索2</head>
<body>
    <form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTU2MDczNTY3OWRkZRXjlQE4H+Z+b5Sk3LxPiqE0viA=" />
</div>

    <div>


     <input type=text value="关键字搜索2" />
    </div>
    </form>
</body>
</html>




这是什么情况?希望高手能解答一下!为什么别的地方可以,单单meta标签内,调用就出问题呢!

------解决方案--------------------
你要是带<head runat="server">
如果你要加多个,可以

HtmlGenericControl m = new HtmlGenericControl("meta");
m.Attributes.Add("name", "Keywords");
m.Attributes.Add("content", "xxx");
 
Page.Header.Controls.Add(m);
m = new HtmlGenericControl("meta");
m.Attributes.Add("name", "Keywords");
m.Attributes.Add("content", "yyy");
Page.Header.Controls.Add(m);

或者
Literal m = new Literal();
m.Text = "<meta name='xx' content='xxx'/><meta name='xx' content='xxx'/><meta name='xx' content='xxx'/>";
Page.Header.Controls.Add(m);