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 %>
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.
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" /> <%}%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With