我試圖禁用input
和runat="server"
屬性。這應該基於屬性背後的代碼。這裏是我的方案的一個新的.NET 3.5 Web窗體項目的精簡攝製:根據屬性後面的代碼將runat =「server」的輸入設置爲禁用
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.IsReadOnly = true;
}
public bool IsReadOnly { get; set; }
}
<%= IsReadOnly %>
<input value="testing" runat="server" id="myinput" disabled="<%# IsReadOnly %>"/>
輸入是不呈現爲禁用。
我在做什麼錯?我已經試過各種事情沒有影響,其中包括:
disabled="<%= IsReadOnly %>"
:沒有禁用,即使IsReadOnly = true
disabled='<%= IsReadOnly ? "disabled" : "" %>'
:不工作的時候IsReadOnly = false
<%= IsReadOnly ? "disabled='disabled'" : "" %>
,在標籤內:解析錯誤
如何根據屬性後面的代碼禁用aspx中的input
?
爲什麼不在'Page_Load'處理程序中執行'myinput.Disabled = IsReadOnly'?請注意,您不能在'runat =「server」'元素中使用'<%='。 – Luaan
這是我目前使用的解決方法。然而,因爲aspx已經有很多其他類似的東西,所以我想把它保留在那裏(或者,當我幾個月後回到這個視圖時,我可能會對輸入的方式感到迷茫禁用)。 – Jeroen