简体   繁体   中英

Webforms meta tag error?

<meta name="keywords" content='<asp:Literal ID="litMetaKeywords" runat="server" />'/>
<meta name="description" content='<asp:Literal ID="litMetaDescription" runat="server" />'/>

I have found the above code in a Web App I am working on. I am getting the following error

The name 'litMetaDescription' does not exist in the current context

And the same for litMetaKeywords . If the asp:literal was not in this meta tag the code would be working. What is a meta tag? Whats its use? Is it what is causing my error?

Putting <asp:Literal> tag inside content attribute won't make it accessible from the code behind. You can use a combination of protected variables and inline code instead.

Code behind:

protected string MetaKeywords;
protected string MetaDescription;

protected void Page_Load(object sender, EventArgs e)
{
    MetaKeywords = "values for meta keywords";
    MetaDescription = "values for meta description";
}

aspx:

<meta name="keywords" content='<%= MetaKeywords %>'/>
<meta name="description" content='<%= MetaDescription %>'/>

For more information about HTML meta tags, see here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM