ASP.NET - Dynamic ModalPopupExtender

淺唱寂寞╮ 提交于 2019-12-20 04:23:02

问题


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!


回答1:


I would do it thusly:

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

then javascript:

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

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, JP

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




回答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.



来源:https://stackoverflow.com/questions/965869/asp-net-dynamic-modalpopupextender

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!