I have an ASP.NET web form where I do not want the markup processed at all based on page/compiler directives. Example:
<%@ Page ... CompilerOptions="/d:MY_FLAG" %>
<% #if MY_FLAG %> ... <% #endif %>'
I have controls in the #if block that refer to code-behind methods which are not included in the build unless a similar #define is set. The problem is that no matter how I implement conditional markup, the runtime checks for the existence of the methods within the block, even if the block is not going to be rendered. So with no method for a control that won't even exist, an exception is thrown at runtime.
I can code around this by injecting markup at runtime depending on a compiler directive in code-behind. I just want to understand why this isn't working.
To be clear, if we put #if FOO
code in markup, VS will disable it and it doesn't get processed in any way in the build or run-time. I want the same functionality for markup.
That's it on my description. The following are just references to similar notes.
A note here says you can't re-use control names within conditional code. Apparently this is because of the issue above - the compiler Does process control names even if they're not going to be used.
This page and the related page by K Scott Allen (Ode to Code) describe conditional markup but that doesn't cover for the situation described here.
And this page describes conditional markup where the decision is made at run-time. I don't want the decision to be made at run-time. That's the problem - the run-time will attempt to verify that the code-behind supports the markup. In my case, if the markup doesn't 'exist' then it won't need to do that.