Search code examples
asp.netmodalpopupextender

activate ModalPopupExtender witheout giving it TargetControlID in asp.net


how can i activate a ModalPopupExtender, whiteout giving the TargetControlID a button id in the aspx page (i dont know wiche button will activate the ModalPopupExtender i have a multiple buttons on my page)

thanks


Solution

  • you must have one TargetControlID but you can hide it and activate the pop up with a different button:

    <div style="display:none;">
        <asp:LinkButton runat="server" ID="lbPrivacy" Text="PRIVACY"/>
        </div>
            <asp:ModalPopupExtender ID="MpePrivacy" runat="server" TargetControlID="lbPrivacy"
    
    <asp:LinkButton runat="server" ID="lbPrivacy2" Font-Underline="true" 
            CausesValidation="false" OnClick="btMpePrivacy_Click">Privacy</asp:LinkButton>
    
    protected void btMpePrivacy_Click(object sender, EventArgs e)
    {
        AjaxControlToolkit.ModalPopupExtender modalPop = ((AjaxControlToolkit.ModalPopupExtender)(this.Master.FindControl("ContentPlaceHolder1").FindControl("MpePrivacy")));
        modalPop.Show();
    }