Reputation: 2047
<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?
Upvotes: 0
Views: 297
Reputation: 14614
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.
Upvotes: 2