Reputation: 11607
I have the following html on my website:
<meta name="keywords" content="<%=Keywords%>"/>
<meta name="description" content="<%=Description%>"/>
This is in the master page for my site. In the code behind for the master page, I have this:
private String _description = "A default description for my site";
public String Description
{
get { return _description; }
set { _description = value; }
}
private String _keywords = "my Site my Company keywords ";
public String Keywords
{
get {return _keywords; }
set { _keywords = value; }
}
The idea is that all the pages on my site will have a default description/keywords, unless I need to set them to something else on a particular page (using Master.Description = "whatever"
).
However, I am having some troubles: the opening bracket for the inline code block delcarations are escaped in the generated HTML, so the code blocks don't work. Here is an excerpt of the generated html for my page:
<meta name="keywords" content="<%=Keywords%>" /><meta name="description" content="<%=Description%>" />
I'm used to using C#, but I'm new to asp.net, and I can't work out the right syntax to get this working correctly. What do I need to do to get inline code blocks working right?
Upvotes: 1
Views: 702
Reputation: 94643
Use simple/single binding expression.
<meta name="keywords" content="<%# Keywords%>"/>
<meta name="description" content="<%# Description%>"/>
Issue the DataBind()
method in code-behind:
if(!IsPostBack)
DataBind();
Upvotes: 0
Reputation: 103388
Run your controls server side and assign values there:
<meta name="keywords" id="keywords" runat="server" />
<meta name="description" id="desc" runat="server" />
keywords.Attributes("content") = Keywords;
desc.Attributes("content") = Description;
Upvotes: 1