开发者

Is it possible to have a Conditional Compilation for ASP.NET comment?

I'd like to do something like this

<# if ANYPREPROCESSORCONSTANT #>
<%--
<# endif #>

Is it possible (I want to put an asp.net COMMENT conditionally, I don't want to call a method conditionaly) ?

Update: seems impossible finally nobody c开发者_C百科ould give any right answer :)


You can do this:

<% #if DEBUG %>
<div id="debug"></div>
<% #else %>
<div id="release"></div>
<% #endif %>

Though it's not very readable in my opinion...use it only if needed!


Yes, you define compilier constants for a Web Site project in the web.config, as shown below. Note the comment must be fully enclosed within the #if...#end if construct. Otherwise, you are commenting out the #end if.

<system.codedom>
    <compilers>
        <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
            <providerOption name="CompilerVersion" value="v3.5"/>
            <providerOption name="WarnAsError" value="false"/>
        </compiler>
        <compiler compilerOptions="/d:DEBUG,TRACE,DEBUG_SURVEYCODE,GPT,TRACE_ARGS,TRACE_ARGS_OUTPUT,TRACE_FILES,DEBUG_USER" language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
    </compilers>
</system.codedom>

 <% #if TRACE_ARGS_OUTPUT %>
 <!-- this traces output comment -->
 <% #end if %>
 <% #if TRACE_ARGS_OUTPUT = FALSE %>
 <!-- this does not output comment -->
 <% #end if %>


Since you said design time, I'm assuming you're referring to Server Control Design Support?

You will have to handle the conditional in your design-time code behind...

#if SOMEDEFINE
DoSomething();

#endif

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜