如何设置TargetContrlID在ModalPopupExtender在一个GridView控件 [英] How to set TargetContrlID in ModalPopupExtender with a control in a GridView
问题描述
如何设置 TragetContriID
到超链接
这是一个里面的GridView
?
我试过这样:
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
PopupControlID="Panel1"
CancelControlID="btnCancel"
OnCancelScript="HideModalPopup()"
TargetControlID="GridView1$HyperLink1">
</asp:ModalPopupExtender>
不过,我有一个错误:没有 GridView1 $ HyperLink1
推荐答案
设置的TargetControlID
的 ModalPopupExtender
基本触发ModalPopup的客户端播放功能,单击控件时。所以,你需要接线了控制自己。
Setting the TargetControlID
of the ModalPopupExtender
basically trigger the client side Show function of that ModalPopup when the control is clicked. So you need to wire up the controls yourself.
首先,由于 ModalPopupExtender
需要的TargetControlID
,您应该添加一个虚拟控制的模式弹出链接
First, since the ModalPopupExtender
need a TargetControlID
, you should add a dummy control to link the modal popup to :
<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。
So the ModalPopupExtender
now has a target that do nothing. Now we now need to do the target's job. You need a javascript function to show the ModalPopup from client side.
<script type="text/javascript">
var ModalPopup='<%= ModalPopupExtender1.ClientID %>';
function ShowModalPopup() {
// show the Popup
$find(ModalPopup).show();
}
</script>
那么你应该在你的 GridView控件
控件的的OnClientClick
事件映射到这个JavaScript函数。从code,我看你使用 ASP:超链接
,我不认为它支持的OnClientClick
事件,所以你可能需要将其切换到 ASP:LinkButton的
Then you should map the OnClientClick
event of the control in your gridview
to this javascript function. From your code, I see that you use a asp:HyperLink
, I don't think it support the OnClientClick
event, so you probably need to switch it to a asp:LinkButton
.
<asp:LinkButton ID="LinkButton1" runat="server"
OnClientClick="ShowModalPopup()" />
这篇关于如何设置TargetContrlID在ModalPopupExtender在一个GridView控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!