我可以在asp的标记中执行类似的操作吗.net页面,基于"定义调试常量"设置?
#IF (DEBUG) THEN
<asp:TextBox ID="TextBox1" runat="server">You're in debug mode</asp:TextBox>
#END IF
我可以在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>