asp.net - Asp.net标记是否有#IF DEBUG?

标签 asp.net debugging

我可以基于“定义DEBUG常量”设置在asp.net页的标记中执行类似的操作吗?

#IF (DEBUG) THEN
  <asp:TextBox ID="TextBox1" runat="server">You're in debug mode</asp:TextBox>
#END IF

最佳答案

我能得到的收盘价是:

<asp:Literal id="isDebug" runat="server" />
<script runat="server">
    void Page_Load()
    {
#if DEBUG
        isDebug.Text = "You're in debug mode";
#endif
    }
</script> 

如果您想在Page_Load()事件中添加其他内容,则会给您带来麻烦;上面的文字代码仅在页面/控件后面没有代码时才有效。

如果需要这样做,可以将上面的代码封装到用户控件中,并将该控件包含在感兴趣的页面中。

我的测试用户控件如下所示:
<%@ Control Language="C#" AutoEventWireup="true"  %>
<asp:Literal id="isDebug" runat="server" />
<script runat="server">    
    void Page_Load()    
    {
#if DEBUG        
        isDebug.Text = "You're in debug mode";
#endif    
    }
</script> 

关于asp.net - Asp.net标记是否有#IF DEBUG?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/378982/

相关文章:

asp.net - 如何在 ASP.NET 2.0 应用程序中为 API 调用启用 TLS 1.2?

c# - 从 C# 在 asp.net 中动态显示图像

java - 是什么让 SSMS 中的 CyanogenMod 允许堆转储,无论其调试标志如何?

perl - *** 检测到 glibc *** perl : double free or corruption (! prev): 0x0c2b7138 ***

jquery - 当asp.net按钮单击事件完成时运行jquery函数

asp.net - 按钮禁用..但是

c# - ASP.NET 中同一 gridview 行中的多个记录

ios - Debug模式下蓝色和黑色有什么区别?

c++ - 你能把这个调试宏从 C++ 翻译成 Python 吗?

javascript - 按下 html 按钮时显示网页的 html 代码