2012-11-19 49 views

回答

2

絕對最簡單和最骯髒的方法是: -

// YourCondition defined as public property of the .aspx page 
<% if (YourCondition != true) { %> 
Your conditional text. 
<% } %> 
+0

如果在你的PageLoad段落中出現「YourCondition」? 它說:當dtusers \t是我的「YourCondition」 –

+0

時,當前上下文中不存在名稱'dtusers'是的,我實際上打算讓您將布爾表達式的YourCondition位替換爲true。不明確的道歉。 –

1

在你的ASPX:

<asp:Label runat="server" id="conditionalLabel" visible="false" /> 

在你的後臺代碼:

private void Page_Load() 
{ 
    if(!conditionToCheck) 
    { 
     conditionalLabel.Visible = true; 
     conditionalLabel.Text = "This is my label text"; 
    } 
} 
-1

安德魯的解決方案更優雅,但如果你感覺有點噁心,那麼有一個更簡單的方法。缺點是這種方法無法控制消息的放置位置。它將顯示在檢查時已經被緩衝/發射的任何HTML之間:

private void Page_Load() 
{ 
    if(!conditionToCheck) 
    { 
     Response.Write("You messed up!"); 
    } 
}