Q:
I want to add favicon.ico
to my web application .so i add the icon to my solution then, i write the following:
<link rel="shortcut icon" href="<%=ResolveUrl("~/favicon.ico")%>"/>
every thing is okay.
<link rel="shortcut icon" href="<%=ResolveUrl("~/favicon.ico")%>"/>
shows the following error :
The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>).
If i use <%#
instead and :
protected override void OnLoad (EventArgs e)
{
base.OnLoad (e);
Page.Header.DataBind ();
}
Is this less performance ?and how to fix this problem?
You dont need to use any form of databinding, simply put runat="server" and the runtime will pares the tag as a GenericHtmlControl and the Url attribute will be resolved in the same manner as a normal ASP.Net ServerControl.
<link rel="shortcut icon" runat="server" href="~/favicon.ico" />
// will render as
<link rel="shortcut icon" href="favicon.ico" />