2012-11-19 5 views

답변

2

절대 간단하고 더러운 방법 : - 귀하의 ASPX에서

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

"YourCondition"이 PageLoad 단락에있는 경우 어떻게됩니까? 그것은 말합니다 : dtusers \t이 "YourCondition"일 때 현재 컨텍스트에 'dtusers'라는 이름이 없습니다. –

+0

그래, 실제로 YourCondition 비트를 true로 평가하는 부울 표현식으로 대체하려고합니다. 그게 분명하지 않은 것에 대한 사과. –

1

:

<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

앤드류의 솔루션은 더 우아하고, 그러나 당신이 hackish를 느끼고 있다면 약간 더 간단한 방법이 있습니다. 단점은이 방법이 메시지가 배치되는 위치를 제어 할 수 없다는 점입니다. 확인을 할 때 이미 버퍼링/방출 된 HTML 사이에 표시됩니다.

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