Search code examples
asp.netasp.net-ajaxajaxcontroltoolkitmodalpopupextender

Calling a modal popup with TargetControl in another UpdatePanel in ASP.NET


I'm trying to call a Modal Popup, but the TargetControl is in a different UpdatePanel than where the ModalPopupExtender resides.

Here's the code:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>
    </ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server"  UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Panel ID="Panel1" runat="server">
        Test
        </asp:Panel>
        <cc1:ModalPopupExtender ID="Panel1_ModalPopupExtender" runat="server" 
            DynamicServicePath="" Enabled="True" TargetControlID="LinkButton1" PopupControlID="Panel1">
        </cc1:ModalPopupExtender>
    </ContentTemplate>
</asp:UpdatePanel>

When I run the page the error "An extender can't be in a different UpdatePanel than the control it extends." is shown.

I'm trying to put a Triggers statement in the UpdatePanel2 but nothing changes:

<Triggers>
        <asp:AsyncPostBackTrigger ControlID="LinkButton1" EventName="Click" />
    </Triggers>

Is possible to do that? Thanks


Solution

  • Move the extender to the first update panel:

        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>
                    <ajaxToolkit:ModalPopupExtender ID="Panel1_ModalPopupExtender" runat="server" 
                DynamicServicePath="" Enabled="True" TargetControlID="LinkButton1" PopupControlID="Panel1">
            </ajaxToolkit:ModalPopupExtender>
    
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:UpdatePanel ID="UpdatePanel2" runat="server"  UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Panel ID="Panel1" runat="server">
            Test
            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>