Search code examples
asp.netasp.net-ajaxmodalpopupextender

Trying to self contain pop ups which use the AjaxToolkit ModalPopUpExtender


I have 3 different kinds of ajax popups that need to exist across my site. I was hoping that I could simply create a user control for each one and place the panel and modal popup extender inside each one but this doesn't seem to be working. Has anyone tried this before or do you have a recommendation as to how I can avoid duplicate code for each pop up on different pages? Thanks!


Solution

  • Ah I figured out my issue with the User Control I believe.

    The ModalPopUpExtender requires the TargetID property to be set otherwise an error occurs. Since this is sitting in a UserControl I just created a dummy link button that doesn't do anything and I set the property visible to false.

        <asp:LinkButton ID="lnkBlank" runat="server" Visible="false" />
        <asp:Panel ID="plContainer" style="display: none;" runat="server">
                Hello?
        </asp:Panel>
        <cc1:ModalPopupExtender ID="mpe" runat="server" 
                BehaviorID="test"
                TargetControlID="lnkBlank" 
                PopupControlID="plContainer" />
    

    Apparently it doesn't appreciate that and the moment I set the visible property to true it started working. Not sure what the reasoning is for a TargetID since, I would think, most pop ups could be called from multiple links about the page. Perhaps I'm still not entirely clear on how this control is supposed to be used.