Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional compile in .aspx files

Tags:

asp.net

I need the the .ASPX file to behave differently based on a conditional compilation symbol.

Let's say as an easy example:

<%@ Control Language="C#" AutoEventWireup="true" (...) %>
<% #ifdef DEBUG %>
     <asp:SomeDebugControlHere runat="server"/>
     .. well .. a LOT of code here
<% #else %>
    <asp:SomeReleaseControlHere runat="server"/>
    .. and a LOT of other code here
<% #endif %>

Later Edit: a few more clarifications. The problem is that the class SomeDebugControlHere is not even defined in the release build (it's way more complicated in real-life, but bear with this example). So in the page.aspx.designer.cs I need to get this in the debug build:

/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.SomeDebugControlHere myControl

and this in the release build: (and never both)

/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.SomeReleaseControlHere myControl

Obviously I need the mark-up in the ASPX file to be different, but I need the designer.cs file to be modified as well to incorporate the new objects/classes.

I'm just hoping somebody knows of a clever way of doing this either by some control inheritance, anything that would allow me to specify different control classes depending on compilation build settings.

like image 665
Radu094 Avatar asked Mar 09 '10 12:03

Radu094


1 Answers

Your if just needs a tweak, should be:

<% #if DEBUG %>

If you want it to behave like a set of C# code would.

like image 58
Nick Craver Avatar answered Dec 02 '22 18:12

Nick Craver