You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

DevExpress开发中保存按钮条件化启用/禁用失效问题求助

Fixing DevExpress ASPxButton Enabled/Disabled Logic

Hey there! Let's tackle why your "Enregistrer" button stays enabled no matter the condition. From the code snippet you shared, it looks like you're only handling the Condition == A case, but not explicitly setting the button to disabled when Condition matches B. Here's how to fix this:

1. Simplest Approach: Set ClientEnabled in Code-Behind

The cleanest way to handle this is to set the button's ClientEnabled property directly in your server-side code (like Page_Load or a data binding event). This avoids messy front-end conditionals and ensures all cases are covered:

protected void Page_Load(object sender, EventArgs e)
{
    // Assuming "Condition" is a variable accessible in your code-behind
    BtSavelisteningScale.ClientEnabled = (Condition == A);
    // This will enable the button when Condition == A, disable it otherwise (Condition == B)
}

2. Fix the Front-End Conditional Syntax

If you prefer to handle it directly in the ASPX markup, make sure you cover both conditions explicitly. Your current code only sets ClientEnabled="true" when Condition is A—when it's B, the button uses its default ClientEnabled="true" value. Here's how to fix that:

Option A: Use a Binding Expression

<td>
    <dx:ASPxButton ID="BtSavelisteningScale" runat="server" 
        HorizontalAlign="NotSet" 
        ImagePosition="Left" 
        Text="Enregistrer" 
        VerticalAlign="NotSet" 
        ClientEnabled='<%# Condition == A %>'
        ClientInstanceName="yourClientInstanceName" />
</td>

Then, in your code-behind, trigger the binding (usually in Page_Load):

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        BtSavelisteningScale.DataBind();
    }
    // If the condition can change on postback, call DataBind() there too
}

Option B: Use an Inline Expression

You can also use a ternary operator directly in the attribute:

<td>
    <dx:ASPxButton ID="BtSavelisteningScale" runat="server" 
        HorizontalAlign="NotSet" 
        ImagePosition="Left" 
        Text="Enregistrer" 
        VerticalAlign="NotSet" 
        ClientEnabled="<%= Condition == A ? true : false %>"
        ClientInstanceName="yourClientInstanceName" />
</td>

Quick Troubleshooting Checks

  • Double-check that your Condition variable is correctly evaluating to A or B. Sometimes typos (like mismatched case, incorrect enum values, or string comparison issues) can break the logic.
  • If the condition changes after a postback, make sure you re-set the ClientEnabled property in the appropriate postback event (e.g., Button_Click, GridView_RowDataBound).

内容的提问来源于stack exchange,提问作者user8805723

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:22:24