Setting ModalPopupExtender TargetControlID to LIstView Button

百般思念 提交于 2019-12-20 05:47:22

问题


I am wondering how I am able to set the TargetControlID of my ModalPopupExtender to the Button on my ListView.

The button that I am trying to set the TargetControlID to is in the Alternating and Item template on the ListView. So I believe I would need to set the TargetControlID to either two buttons, or have two different ModalPopupExtenders.

Here is my ModalPopupExtender:

<cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panl1" TargetControlID="Button1"
    CancelControlID="Button2" BackgroundCssClass="Background"  OnLoad="mp1_Load">
</cc1:ModalPopupExtender>

And here is the alternating template for my listview:

<AlternatingItemTemplate>
 <!--Input fields that do not apply to the question-->
 ..
 ..
 ..
<asp:Button ID="Button1" runat="server" Text="Show Popup" />
</AlternatingItemTemplate>

This will be the exact same setup for the ItemTemplate.


回答1:


You could use java-script to do the job instead:

<a id="showModalPopupClientButton" href="#">Open pop-up</a>
<a id="hideModalPopupViaClientButton" href="#">Close pop-up</a>

<script type="text/javascript">

    // Add click handlers for buttons to show and hide modal popup on pageLoad
    function pageLoad() {
        $addHandler($get("showModalPopupClientButton"), 'click', showModalPopupViaClient);
        $addHandler($get("hideModalPopupViaClientButton"), 'click', hideModalPopupViaClient);        
    }

    function showModalPopupViaClient(ev) {
        ev.preventDefault();
        var modalPopupBehavior = $find('programmaticModalPopupBehavior');
        modalPopupBehavior.show();
    }

    function hideModalPopupViaClient(ev) {
        ev.preventDefault();        
        var modalPopupBehavior = $find('programmaticModalPopupBehavior');
        modalPopupBehavior.hide();
    }
</script>

UPDATE (using server side) You need to set a fake server button(display: none) as a target control id to your popup extender first:

 <asp:Button ID="Button1" runat="server" Style="display: none;" />
 <cc1:ModalPopupExtender ID="mp1" runat="server" 
    PopupControlID="Panl1"      TargetControlID="Button1"
    CancelControlID="Button2" BackgroundCssClass="Background"  
    OnLoad="mp1_Load">
</cc1:ModalPopupExtender>

on your code behind whenever you want to display or close the popup, you just need to call the following functions:

  mp1.Show();    //to display popup

  mp1.Hide()     //to close popup


来源:https://stackoverflow.com/questions/28726722/setting-modalpopupextender-targetcontrolid-to-listview-button

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