Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET WebForms "Identifier expected" error

I added this line of code into my ASP.NET Web Forms application:

<link rel="stylesheet" href="css/icomoon.css" media="print" onload="this.media='all'">

This code is in the Site.Master masterpage.

And I am now getting an error:

Identifier Expected

If I remove the media and onload properties there is no error:

<link rel="stylesheet" href="css/icomoon.css">

Does ayone know how to fix this? Seems like some kind of issue related to onload getting parsed on the server I just don't know how to escape it. Any help would be greatly appreciated.

like image 955
A X Avatar asked Nov 18 '25 23:11

A X


2 Answers

I can't find some article that can describe why it's happening. I just test it that's why I'm sharing it with you if it will solve your problem.

Do you have something like this on your Site.Master, <asp:PlaceHolder runat="server">...</asp:PlaceHolder> inside the <head>...</head>?
If no try to create one inside the <head>..</head>, if yes, put the link inside this <asp:PlaceHolder runat="server">...</asp:PlaceHolder>.

<head runat="server">

   ...

    <asp:PlaceHolder runat="server">
        ...
        <link rel="stylesheet" href="css/icomoon.css" media="print" onload="this.media='all'">
        ...
    </asp:PlaceHolder>

    ...

</head>
like image 111
tontonsevilla Avatar answered Nov 20 '25 14:11

tontonsevilla


Just like you discovered, using the onload in the CSS link tag gives an error when used in the head section on MASTER pages.

To get rid of the error, place the CSS <link..> just below the body tag on the master page. Tested it on my end and it worked fine.

 <body>
  <link rel="stylesheet" href="css/icomoon.css" media="print" onload="this.media='all'" />
   <%- other code --%>
 </body>
like image 29
Jamal Avatar answered Nov 20 '25 14:11

Jamal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!