Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an #IF DEBUG for Asp.net markup?

Can I do something like this in the markup of an asp.net page, based off the "Define DEBUG constant" setting?

#IF (DEBUG) THEN
  <asp:TextBox ID="TextBox1" runat="server">You're in debug mode</asp:TextBox>
#END IF
like image 533
Sisiutl Avatar asked Dec 18 '08 19:12

Sisiutl


People also ask

Is there a or is there any?

Which One Should You Use: Is There A or Is There Any? We must use 'a' with singular countable nouns and 'any' with uncountable nouns. We use 'is' with both singular countable nouns and uncountable nouns. Remember, uncountable nouns do have countable forms of measurement.

Is there or are there grammar?

Use there is when the noun is singular (“There is a cat”). Use there are when the noun is plural (“There are two cats”).

Is their VS is there?

Their is the possessive pronoun, as in "their car is red"; there is used as an adjective, "he is always there for me," a noun, "get away from there," and, chiefly, an adverb, "stop right there"; they're is a contraction of "they are," as in "they're getting married."

Is there are there example?

There is one table in the classroom. There are three chairs in the classroom. There is a spider in the bath. There are many people at the bus stop.


3 Answers

<form runat="server">  <% #if DEBUG %>  <asp:TextBox ID="TextBox1" runat="server">You're in debug mode</asp:TextBox>  <% #else %>  <asp:TextBox ID="TextBox2" runat="server">Mmm... No, I think you're not in debug mode</asp:TextBox>  <% #endif %> </form> 

Note that you cannot assign the same ID for those text boxes.

Also note that DEBUG is true when it is set so in web.config:

<compilation debug="true"> 
like image 84
algiecas Avatar answered Sep 20 '22 21:09

algiecas


The close as I can get is:

<asp:Literal id="isDebug" runat="server" /> <script runat="server">     void Page_Load()     { #if DEBUG         isDebug.Text = "You're in debug mode"; #endif     } </script>  

This would give you problems if you wanted to have anything else in your Page_Load() event; the literal code above only works if the page/control has no code behind.

If I needed to do this, I would encapuslate the above code into a user control and include that control in the pages of interest.

My test user control looks like this:

<%@ Control Language="C#" AutoEventWireup="true"  %> <asp:Literal id="isDebug" runat="server" /> <script runat="server">         void Page_Load()         { #if DEBUG                 isDebug.Text = "You're in debug mode"; #endif         } </script>  
like image 40
jrcs3 Avatar answered Sep 18 '22 21:09

jrcs3


If you are trying to step through javascript or prefer to minify javascript when not debugging, I prefer this approach:

<% if (Debugger.IsAttached) { %>

  <script src="jquery.js"></script>

<% } else { %>

  <script src="jquery.min.js"></script>

<% } %>

I can easily step through code when I am debugging, otherwise I want the scripts to be minified. Be sure to include the following import:

<%@ Import Namespace="System.Diagnostics" %>

Moreover, it is nice to use the Web Essentials visual studio extension to bundle/minify your javascript files so that there is only one request made to the server for your scripts.

like image 39
Gaff Avatar answered Sep 17 '22 21:09

Gaff