有Asp.net标记的#IF DEBUG吗? [英] Is there an #IF DEBUG for Asp.net markup?

查看:120
本文介绍了有Asp.net标记的#IF DEBUG吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <$ c 

我可以在asp.net页面的标记中做出这样的事情吗? $ c> #IF(DEBUG)THEN
< asp:TextBox ID =TextBox1runat =server>您处于调试模式< / asp:TextBox>
#END IF


解决方案

可以得到是:

 < asp:Literal id =isDebugrunat =server/> 
< script runat =server>
void Page_Load()
{
#if DEBUG
isDebug.Text =你处于调试模式;
#endif
}
< / script>

如果您想在您的Page_Load()事件中有其他任何事情,这将给您带来问题;上面的文字代码只有在页面/控件没有代码的情况下才起作用。



如果我需要这样做,我将把上述代码包含在用户控件中,并将该控件包含在感兴趣的页面中。



我的测试用户控件如下所示:

 <%@ Control Language =C#AutoEventWireup =true%> 
< asp:Literal id =isDebugrunat =server/>
< script runat =server>
void Page_Load()
{
#if DEBUG
isDebug.Text =你处于调试模式;
#endif
}
< / script>


Can I do something like this in the markup of an asp.net page, based off the "Define DEBUG constant" setting?

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

解决方案

The close as I can get is:

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

This would give you problems if you wanted to have anything else in your Page_Load() event; the literal code above only works if the page/control has no code behind.

If I needed to do this, I would encapuslate the above code into a user control and include that control in the pages of interest.

My test user control looks like this:

<%@ 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标记的#IF DEBUG吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆