views:

272

answers:

1

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?

+2  A: 
<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.

Zhaph - Ben Duguid
I get the error "The Controls collection cannot be modified because the control contains code blocks (i.e. )."
Jeremy