Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#DEBUG Preprocessor statements in ASPX page

Tags:

I'm trying to use a preprocessor directive in an ASPX page, but the page doesn't recognize it. Is this just something I can't do?

Background: I'm trying to include the full version of jQuery in DEBUG mode (for, well, debugging =) ), and the minified version for release. I tried this, but I'm not terribly familiar with the ASPX <% syntax. Am I just fundamentally misunderstanding what this syntax does?

<% #if DEBUG %> <script type="text/javascript" src="resources/jquery-1.3.2.js" /> <% #else %> <script type="text/javascript" src="resources/jquery-1.3.2.min.js" /> <% #endif %> 
like image 617
Badjer Avatar asked Nov 26 '09 01:11

Badjer


2 Answers

Interesting difference here - using #if DEBUG in the aspx page pulls from the tag in the web.config, but when you use it in the code-behind, it pulls DEBUG from the constant from the build configuration in the project file. So they're actually accessing two different settings.

Thus, as far as I can tell, this isn't actually possible.

like image 56
Badjer Avatar answered Oct 04 '22 06:10

Badjer


To me the most elegant solution would be to simply define a field in code-behind with preprocessor directives and then check for its value from the aspx page.

In code-behind:

public partial class WebClient : System.Web.UI.Page {         #if DEBUG      public bool DebugMode = true; #else     public bool DebugMode = false; #endif } 

Aspx page:

<%if(this.DebugMode){%>     <script type="text/javascript" src="resources/jquery-1.3.2.js" /> <%}%> <%else{%>     <script type="text/javascript" src="resources/jquery-1.3.2.min.js" /> <%}%> 
like image 27
pingo Avatar answered Oct 04 '22 06:10

pingo