简体   繁体   English

带属性的 DropDownButton 条件语句?

[英]DropDownButton conditional statement with attributes?

I'm having trouble to find out how to check if my DropDownList has the attribute Disabled我无法找出如何检查我的DropDownList是否具有禁用属性

Here is my code (of how I declare my DropDownList):这是我的代码(我如何声明我的 DropDownList):

<div class="col-7">
    <asp:DropDownList ID="cmbProperty" runat="server" class="browser-default z-depth-5">
    </asp:DropDownList>
</div>

On page load:在页面加载时:

protected void Page_Load(object sender, EventArgs e)
{
    cmbProperty.Attributes.Add("disabled", "disabled");
}

On button click:单击按钮:

protected void btnCheckMyProperty_Click(object sender, EventArgs e)
{
    if(cmbProperty.Enabled == true)
    {
        // I always get a true statement
    }            
}

Someone has a clue about it?有人知道吗?

Thank you谢谢

Since you commented saying setting cmbProperty.Enabled = false messes with your css, you should check the disabled attribute in your button click event instead of the Enabled property.由于您评论说设置cmbProperty.Enabled = false与您的 css 混淆,因此您应该检查按钮单击事件中的disabled属性而不是Enabled属性。 This is simply:这很简单:

protected void btnCheckMyProperty_Click(object sender, EventArgs e)
{
    if(cmbProperty.Attributes["disabled"] == "disabled")
    {
        // Your code here...
    }            
}

Note: This will NOT error out if the disabled attribute is not set.注意:如果未设置disabled属性,这不会出错。 It will return false in that case...在这种情况下它将返回 false ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM