首页 > 解决方案 > 一旦 Enabled 设置为 false,即使在将其设置回 true 后,用户控件中的确认按钮扩展器也不起作用

问题描述

我有一个用户控件,其中包含一个确认按钮扩展器和一个模式弹出扩展器。看起来像:

<asp:Panel ID="panelConfirmBox" runat="server" Style="display:none;">

<asp:Button ID="btnConfirmSelection" runat="server" CssClass="hidden"/>
<asp:Button ID="btnNo" runat="server" Text="No" />
<asp:Button ID="btnYes" runat="server" Text="Yes" />
              
<asp:ModalPopupExtender Id="popupConfirmBox" runat="server" PopupControlID="panelConfirmBox"  CancelControlID="btnNo" OkControlId="btnYes"  />
<asp:ConfirmButtonExtender ID="btnConfirm" runat="server" DisplayModalPopupID="popupConfirmBox"/> 

</asp:Panel>

用户控件获得一个下拉列表。更改下拉列表选择时,应运行按钮 onclick 事件。在用户控件 aspx.cs 中有以下代码:

public string TargetControlId { set { popupConfirmBox.TargetControlID = btnConfirm.TargetControlID = btnConfirmSelection.ID; } }
public DropDownList DDL { get; set; }
public EventHandler OnClick { set { btnConfirmSelection.Click += value; } }
public bool Enabled { set { btnConfirm.Enabled = value; } get { return btnConfirm.Enabled; } }


protected void Page_Load(object sender, EventArgs e)
{            
       if (DDL != null)
       {
               string script = "$('#" + DDL.ClientID + "').on('change', function () { $('#" + btnConfirmSelection.ClientID + "').click();}); ";
               ScriptManager.RegisterStartupScript(Page, Page.GetType(), "CallChange" + ID, script, true);                 
       }
}

在 aspx 中使用用户控件如下所示:

<asp:DropDownList ID="ddl" runat="server" AutoPostBack="false"  />
<aa:DDLConfirmPopup runat="server" ID="ConfirmPopupSelectionChange" Title="aaa" Message="bbb" TargetControlId=""/>

在 aspx.cs 中:

ConfirmPopupSelectionChange.DDL = ddl;
ConfirmPopupSelectionChange.OnClick = new EventHandler(func);

protected void func(object sender, EventArgs e)
{
}

我有几个用户控件的实例,除了一个之外,大多数都可以正常工作。一旦我设置了属性 Enabled="false",即使我将其设置回 true,它也不会再次显示弹出窗口,而是直接转到 onClick 函数。这是更改启用属性的函数:

private void manageConfirmPopup()
{
    if (---)
       ConfirmPopup.Enabled = true;
    else
       ConfirmPopup.Enabled = false;
}

我看到 enable 属性确实更改正确,但即使将其设置为 true,confirm 也不起作用。

我的代码有什么问题?

谢谢!

标签: javascriptc#asp.net

解决方案


推荐阅读