How to set TargetContrlID in ModalPopupExtender using a control in a GridView

How to set TragetContriID on HyperLink , which is inside GridView ?

I tried this:

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

But I have an error: no GridView1$HyperLink1

+7
source share
2 answers

Setting TargetControlID ModalPopupExtender basically launches the client side. Shows the function of this ModalPopup when the control is clicked. Therefore, you need to connect the controls yourself.

First, since ModalPopupExtender needs a TargetControlID , you must add a dummy control to associate the modal popup with:

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

And the ModalPopupExtender TargetControlID link to it

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

So, ModalPopupExtender now has a target that does nothing. Now we need to do the targeted work. You need a javascript function to show ModalPopup on the client side.

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

Then you must map the OnClientClick event of the control in the gridview to this javascript function. From your code, I see that you are using asp:HyperLink , I don’t think it supports the OnClientClick event, so you probably need to switch it to asp:LinkButton .

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

perfect way to handle it, worked for me

0
source

All Articles