开发者

using #if DEBUG conditional compilation statement in aspx page

I am trying to do something like this in an aspx page:

<head runat="server">
    <% #if DEBUG %>
        <script src="jquery-1.3.2.js" type="tex开发者_如何学Pythont/javascript"></script>
    <% #else  %>
        <script src="jquery-1.3.2.min.js" type="text/javascript"></script>
    <% #endif %>
</head>

I get an error "Preprocessor directives must appear as the first non-whitespace character on a line". How can I do this?


<head runat="server">
  <% 
    #if DEBUG
  %>
    <script src="jquery-1.3.2.js" type="text/javascript"></script>
  <%
    #else
  %>
    <script src="jquery-1.3.2.min.js" type="text/javascript"></script>
  <%
    #endif
  %>
</head>

Works for me - note that this is based on the value of the debug attribute in the <compilation> element of the web.config.

Edit to respond to comment

Ah, so you're also adding controls to the head through the code-behind? Then you'll probably need to be adding this dynamically from the code-behind as well.

If you're happy to always serve the minified version, but want to use IntelliSense in Visual Studio you should ensure that you've installed the hotfix to enable this:

VS2008 SP1 Hotfix to Support "-vsdoc.js" IntelliSense Doc Files

This would enable you to name your non-minified version jquery-1.3.2.min-vsdoc.js and have VS read that one in while you're building the pages.


this is worked for me:

<head runat="server">
    <asp:PlaceHolder runat="server">
    <% 
#if !DEBUG 
    %>
    <meta http-equiv="X-UA-Compatible" content="IE=9" />
    <% 
#else 
    %>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <% 
#endif 
    %>
    </asp:PlaceHolder>
</head>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜