【问题标题】:Setting ModalPopupExtender TargetControlID to LIstView Button将 ModalPopupExtender TargetControlID 设置为 LIstView 按钮
【发布时间】:2015-02-25 18:22:02
【问题描述】:

我想知道如何将ModalPopupExtenderTargetControlID 设置为ListView 上的按钮。

我试图将TargetControlID 设置为的按钮位于ListView 上的Alternating 和Item 模板中。所以我相信我需要将TargetControlID 设置为两个按钮,或者有两个不同的ModalPopupExtenders

这是我的ModalPopupExtender

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

这是我的列表视图的交替模板:

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

这与 ItemTemplate 的设置完全相同。

【问题讨论】:

    标签: c# asp.net listview simplemodal


    【解决方案1】:

    您可以使用 java-script 来代替:

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

    更新(使用服务器端) 您需要首先将一个假服务器按钮(显示:无)设置为您的弹出扩展器的目标控件 ID:

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

    只要你想显示或关闭弹窗,在你的代码后面,你只需要调用以下函数:

      mp1.Show();    //to display popup
    
      mp1.Hide()     //to close popup
    

    【讨论】:

    • 抱歉回复晚了,我正在吃午饭。我会试一试,让你知道它是否有效。
    • 我试了一下,但收到错误消息Cannot read property 'show' of null.。我不相信它会在页面上找到控件。
    • 试试服务端方案,希望对你有帮助
    • 有点混乱,但在你的帮助下我得到了它。谢谢!!
    猜你喜欢
    • 2011-01-28
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 2017-11-27
    • 1970-01-01
    • 2017-01-12
    • 1970-01-01
    相关资源
    最近更新 更多