Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"#if DEBUG" in an ASPX/ASCX page

I want to be able to point to one of 2 assemblies based on what mode (DEBUG or RELEASE) I have selected in my VS2005 IDE. Something like this (which does not work):

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VideoDialog.ascx.cs" Inherits="Company.Web.Base.Controls.VideoDialog" %>

<% #if DEBUG %>
<%@ Register TagPrefix="Company" Assembly="Company" Namespace="Company.UI.Controls.VideoControl" %>
<% #else %>
<%@ Register TagPrefix="Company" Assembly="Company.UI.Controls.VideoControl" Namespace="Company.UI.Controls.VideoControl" %>
<% #endif %>

<Company:CompanyVideo ID="Video1" runat="server"></Company:CompanyVideo>

So, my question is: How do I correctly use a #if DEBUG in an ASPX or ASCX page?

like image 437
Keith Barrows Avatar asked Nov 17 '25 00:11

Keith Barrows


2 Answers

I don't know how to get what you want, but I face the same problem. I do my control references in web.config and then do post build steps to copy the appropriate web.config for release/debug. It works because you need a different web.config for release/debug anyhow (if only for the debug="true" attribute) and because you can have a different post build step for debug and release.

like image 134
MatthewMartin Avatar answered Nov 19 '25 14:11

MatthewMartin


<%
//<compilation debug="false"> in web.config
//*.aspx

#if DEBUG
    Response.Write("<script type=\"text/javascript\">");
    Response.Write("$.validator.setDefaults({ debug: true })");
    Response.Write("</script>");
#endif

%>
like image 43
ohaiyo Avatar answered Nov 19 '25 14:11

ohaiyo