0

I have a favicon that I have to pass from server side. I did it like this:

<link rel="shortcut icon" type="image/ico" href="<%= favIcon%>" />

On the server side I have added a public string named favIcon and then

favIcon = "Generic_Icon_2015.ico";

If I look at the Web Debugger page on chrome i see the result like this

<link rel="shortcut icon" type="image/ico" href="&lt;% = favIcon%>" />

so he wasn't able to recognize the < symbol. I also get

http://localhost/AL07/%3C%%20=%20favIcon%%3E 400 (Bad Request)

I noticed that if I remove runat="server" from <head> then it works fine..

What's happening?

ayasha
  • 1,221
  • 5
  • 27
  • 46

1 Answers1

0

Use Data Bind Code nuggets instead:-

 href="<%# favIcon%>" 

But, you need to call Page.DataBind() method on page load like this:-

protected void Page_Load(object sender, EventArgs e)
{
   if (!IsPostBack)
   {
      Page.DataBind();
   }
}

For reason why your code (Content code nuggets) is not working, Check this answer.

Community
  • 1
  • 1
Rahul Singh
  • 21,585
  • 6
  • 41
  • 56