Asp.net

有條件地排除 ASP.NET WebForms 中的一個 html 塊

  • April 4, 2009

這只是一個簡單的問題:基於伺服器端評估,如何排除伺服器返回的 aspx web 表單上的一段 html?

我不是專門談論控制項,因為它們往往具有可見參數,而只是一些原始 html。

<div id="divYourDiv" runat="server">
   your stuff goes here...
</div>

//Server side code...
public void ShowYourDiv(bool visible)
{
   this.divYourDiv.Visible = visible;
}

有些人反對以下方法,但它沒有人回答,我覺得它應該作為一個選項顯示。如果使用得當,它會很方便。

<% if (ShowLabel) {%>
<label>This will not be shown if the ShowLabel property evaluates false</label>
<%}%>

為了完成這項工作,您將在頁面上擁有一個名為 ShowLabel 的公共或受保護屬性,該屬性返回一個布爾值。

引用自:https://stackoverflow.com/questions/716361