Jeremy
Jeremy

Reputation: 46350

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="text/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?

Upvotes: 3

Views: 3657

Answers (2)

mysticdotnet
mysticdotnet

Reputation: 47

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>

Upvotes: 1

Zhaph - Ben Duguid
Zhaph - Ben Duguid

Reputation: 26956

<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.

Upvotes: 6

Related Questions