是否有Asp.net标记的#IF DEBUG? [英] Is there an #IF DEBUG for Asp.net markup?
本文介绍了是否有Asp.net标记的#IF DEBUG?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以做一个asp.net页面的标记这样的事情,基于该定义DEBUG常数设置?
#IF(调试)THEN
< ASP:文本框ID =TextBox1的=服务器>您是在调试模式下及/ ASP:文本框>
#万一
解决方案
我可以得到接近的是:
< ASP:文字的id =isDebug=服务器/>
<脚本=服务器>
无效的Page_Load()
{
#如果DEBUG
isDebug.Text =你在调试模式;
#万一
}
< / SCRIPT>
这会给你的问题,如果你想别的东西在你的Page_Load()事件;字面code以上只能如果页面/控件没有code后面。
如果我需要做到这一点,我会时封装上述code到用户的控制,包括在相关页面的控制。
我的测试用户的控制是这样的:
<%@控制语言=C#AutoEventWireup =真正的%GT;
< ASP:文字的id =isDebug=服务器/>
<脚本=服务器>
无效的Page_Load()
{
#如果DEBUG
isDebug.Text =你在调试模式;
#万一
}
< / 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屋!
查看全文