[{"data":1,"prerenderedAt":96},["ShallowReactive",2],{"/2025/11/26-if-debug-preprocessor-directive-on-asp.net-web-forms-markup":3},{"id":4,"title":5,"body":6,"date":87,"description":49,"extension":88,"meta":89,"navigation":90,"path":91,"robots":92,"seo":93,"stem":94,"__hash__":95},"posts/2025/11/26 if-DEBUG-preprocessor-directive-on-ASP.NET-Web-Forms-markup.md","26 If DEBUG Preprocessor Directive On ASPNET Web Forms Markup",{"type":7,"value":8,"toc":84},"minimark",[9,18,25,28,31,33,36,50,52,55,63,65,76],[10,11,13],"post-title",{":date":12},"date",[14,15,17],"h1",{"id":16},"if-debug-preprocessor-directive-on-aspnet-web-forms-markup","#if DEBUG Preprocessor Directive on ASP.NET Web Forms Markup",[19,20,21],"notes",{},[22,23,24],"p",{},"This is a repost from my old blog. First posted in 4/21/2020.",[26,27],"br",{},[22,29,30],{},"I have a JavaScript that I want to include only on Release mode of my ASP.NET Web Forms app. The script will reside in the markup. To do that I will need to use #if DEBUG. But to have it working in the markup takes me a while to figure out.",[26,32],{},[22,34,35],{},"First, I tried wrapping my script with the following code on the markup under  tag and it doesn't work.",[37,38,39],"code-block",{},[40,41,46],"pre",{"className":42,"code":44,"language":45},[43],"language-text","\u003C% #if !DEBUG %>\n    \u003Cscript>\n         alert('Hello World!');\n    \u003C/script>\n\u003C% #endif %>\n","text",[47,48,44],"code",{"__ignoreMap":49},"",[26,51],{},[22,53,54],{},"Next, after reading some articles online, I tried to wrap my code using the following code and it still doesn't work.",[37,56,57],{},[40,58,61],{"className":59,"code":60,"language":45},[43],"\u003C% if (!Debugger.IsAttached) { %>\n    \u003Cscript>\n        alert('Hello World!');\n    \u003C/script>\n\u003C% } %>\n",[47,62,60],{"__ignoreMap":49},[26,64],{},[22,66,67,68,75],{},"Finally, the one that works for me is when I wrap the whole thing with ",[47,69,74],{"className":70},[71,72,73],"bg-gray-200","p-2","rounded","\u003Casp:PlaceHolder>"," tag:",[37,77,78],{},[40,79,82],{"className":80,"code":81,"language":45},[43],"\u003Casp:PlaceHolder runat=\"server\"> \n    \u003C% #if !DEBUG %>\n        \u003Cscript>\n            alert('Hello World!');\n        \u003C/script>\n    \u003C% #endif %>\n\u003C/asp:PlaceHolder>\n",[47,83,81],{"__ignoreMap":49},{"title":49,"searchDepth":85,"depth":85,"links":86},2,[],"2025-11-26T00:00:00.000Z","md",{},true,"/2025/11/26-if-debug-preprocessor-directive-on-asp.net-web-forms-markup",null,{"title":5,"description":49},"2025/11/26 if-DEBUG-preprocessor-directive-on-ASP.NET-Web-Forms-markup","JWVABo3YVyE_8gWrFgBUWIctVrzyFx1rYjFxEnVLJPc",1785167452435]