【问题标题】:How to set TargetContrlID in ModalPopupExtender with a control in a GridView如何使用 GridView 中的控件在 ModalPopupExtender 中设置 TargetContrlID
【发布时间】:2011-08-20 19:08:57
【问题描述】:

如何将TragetContriID 设置为HyperLink 中的GridView

我试过了:

<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
                        PopupControlID="Panel1" 
                        CancelControlID="btnCancel" 
                        OnCancelScript="HideModalPopup()"
                        TargetControlID="GridView1$HyperLink1">
</asp:ModalPopupExtender>

但我有一个错误:没有GridView1$HyperLink1

【问题讨论】:

    标签: asp.net gridview ajaxcontroltoolkit modalpopupextender


    【解决方案1】:

    设置ModalPopupExtenderTargetControlID 基本上会在单击控件时触发该ModalPopup 的客户端显示功能。所以你需要自己连接控件。

    首先,由于ModalPopupExtender 需要TargetControlID,您应该添加一个虚拟控件以将模式弹出窗口链接到:

    <asp:Button runat="server" 
                ID="HiddenTargetControlForModalPopup" 
                style="display:none"/> 
    

    并将ModalPopupExtender TargetControlID 链接到它

    <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
                            PopupControlID="Panel1" 
                            CancelControlID="btnCancel" 
                            OnCancelScript="HideModalPopup()"  
                            TargetControlID="HiddenTargetControlForModalPopup">
    </asp:ModalPopupExtender>
    

    所以ModalPopupExtender 现在有一个什么都不做的目标。现在我们需要完成目标的工作。您需要一个 javascript 函数来从客户端显示 ModalPopup。

    <script type="text/javascript">
         var ModalPopup='<%= ModalPopupExtender1.ClientID %>';
    
         function ShowModalPopup() {
             //  show the Popup     
             $find(ModalPopup).show();
         }
    </script>   
    

    然后您应该将gridview 中控件的OnClientClick 事件映射到此javascript 函数。从您的代码中,我看到您使用了asp:HyperLink,我认为它不支持OnClientClick 事件,因此您可能需要将其切换为asp:LinkButton

    <asp:LinkButton ID="LinkButton1" runat="server" 
                    OnClientClick="ShowModalPopup()" />
    

    【讨论】:

    • 您好,我正在使用您的代码,但出现错误。Microsoft JScript 运行时错误:Sys.ArgumentNullException:值不能为空。参数名称:handler
    • 对我来说很好,经过良好测试的解决方案。您的错误可能在其他地方。尝试调试它以查看错误发生的位置。
    • 如何修复错误。但它没有触发弹出(消息框)。
    • @software 好吧,如果这对您有所帮助,我们将不胜感激对这个问题和这个答案进行投票。
    • @DavRob60 似乎将 Gridview 放置在 UpdatePanel 中,但将弹出窗口保留在其外部就可以了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-13
    • 1970-01-01
    • 1970-01-01
    • 2011-01-02
    • 1970-01-01
    相关资源
    最近更新 更多