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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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>

Method 2

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>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x