不使用TargetControlID进行服务器控制

时间:2013-10-02 18:56:02

标签: c# asp.net

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

<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();
        }

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

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

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