简体   繁体   中英

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.

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM