不使用 TargetControlID 进行服务器控制

本文关键字:服务器 控制 TargetControlID | 更新日期: 2023-09-27 18:33:42

我正在使用两个导致弹出窗口的服务器控件。一种是按下按钮的原因。第二个不需要依赖于操作事件,而是以编程方式发生。这是第二个的代码:

<div>
    <ajaxToolkit:ModalPopupExtender ID="ModalPopupChangeAssociations" runat="server" TargetControlID="Button1" PopupControlID="changeAssociationsPanel"
        PopupDragHandleControlID="PopupHeader" Drag="true">
    </ajaxToolkit:ModalPopupExtender>
    <asp:Button ID="Button1" runat="server" Text="Button" />
    <asp:Panel ID="changeAssociationsPanel" runat="server" CssClass="changeAssociationsPanel">
        <h2>This theme type is currently assigned to themes. What would you like to do?</h2>
        <asp:Button ID="removeAssignmentButton" runat="server" Text="Remove all Associated Assignments"
            OnClick="removeAssignmentButton_Click" />
        <asp:Button ID="changeAssignmentButton" runat="server" Text="Change all Associated Assignments"
            OnClick="changeAssignmentButton_Click" />
        <asp:Button ID="cancelAssignmentButton" runat="server" Text="Cancel" OnClick="cancelAssignmentButton_Click" />
        <asp:Panel ID="reassignPanel" runat="server" Visible="false">
            <asp:Label ID="reassignThemeTypeLabel" runat="server" Text="New Theme Type:"></asp:Label>
            <asp:DropDownList ID="reassignThemeTypeDropDown" runat="server" DataSourceID="SqlDataSource2"
                DataTextField="Type" DataValueField="PK_ThemeType">
            </asp:DropDownList>
            <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                SelectCommand="SELECT [Type], [PK_ThemeType] FROM [ThemeType] WHERE [Deleted] = 0 ORDER BY [Type] ASC"></asp:SqlDataSource>
            <asp:Button ID="reassignThemeTypeSubmitButton" runat="server" Text="Submit" OnClick="reassignThemeTypeSubmitButton_Click" />
        </asp:Panel>
    </asp:Panel>
</div>

第二个按钮上附加了一个按钮,不必如此。我不需要它,它就在那里,因为如果我删除它,我会收到错误:

The TargetControlID of 'ModalPopupChangeAssociations' is not valid. The value cannot be null or empty.

我以编程方式调用它:

        if (checkIfAssociationExist(sqlQueryReturnString(getThemeTypePK)))
        {
            ModalPopupChangeAssociations.Show();
        }

如何摆脱按钮,以便我可以以编程方式使用此特定的服务器控件?

不使用 TargetControlID 进行服务器控制

最初可以将其分配给隐藏字段,然后在需要时以编程方式将其更改为所需的控件。

我不确定,您可以使用标签作为目标ID。如果没有标签,则可以添加标签并将可见属性设置为 false。