我可以基于“定义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/