ASP.NET – Dynamic ModalPopupExtender

I have an ASP.NET page that has dynamically created LinkButton elements. Please note that these LinkButton elements are not added to a DataGrid, GridView, or Repeater.

When a user clicks on one of these LinkButton elements, I want to display a dialog box. To accomplish this, I was attempting to use a ModalPopupExtender and set its TargetControlID when a user clicked one of the LinkButton elements. Unfortunately this is not working.

Does anyone know how I can use the same ModalPopupExtender with multiple LinkButton elements?

Thank you!

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

I would do it thusly:

<a href="#" rel="nofollow noreferrer noopener" onclick="doPopUp()" Text="SomeLinkButton Lookalike" />
<asp:LinkButton runat="server" ID="someHiddenButton" CssClass="hidden" />

then javascript:

function doPopUp(){
    var somehiddenbutton = 
        document.getElementById('<%= someHiddenButton.ClientID %>');;

Then you can simply have a runat server linkbutton with CSS property display:none, and that will be your TargetControlID for your ModalPopupExtender.

Hope this helps,

EDIT: I didn’t include the .click() method. dunce moment

Solution 2

If you can post a bit of code then it will surely help. For now I can suggest to have a hidden button as TargetControl and then use the Show method of the ModalPopUp to display it on link button click.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply