简体   繁体   中英

ASP.Net AJAX modal popup window

First I'll describe the web form layout:

The form contains a GridView1 with a "Details" button that opens a second GridView2, whose purpose of course is to show details of the item selected from parent GridView1. All controls are rendered dynamically in the server-side codebehind.

The Challenge:

I need to create a modal pop-up window that's presented when the user clicks an icon that's in child GridView2 as an Image control in a TemplateField. This is so users can add comments to the details in child GridView2.

My approach:

I'm trying to get the AJAXToolKit's modal popup extender (ID = "mpe") wired to the icon in the TemplateField during the PreRender stage. Since the TargetControlID cannot be null or empty, what I'm doing is creating a dummy Button control and setting the modal popup extender's TargetControlID property to the dummy button's ID called, then after the TemplateField is added to GridView2, I set the TargetControlID property to the icon's ID, which is "icon_addComment".

The Problem:

When I try to set the TargetControlID property to the icon's ID, the code throws the error " The TargetControlID of 'mpe' is not valid. A control with ID 'icon_addComment' could not be found. ". I'm stumped on how I can get this to work properly, it seems there's no way getting around the condition that the Target Control must be created before the modal popup extender. What I'd like is to just have the child GridView2 icon's ID be the TargetControlID for the modal popup extender

Use a dummy hidden button as a target control id to the modal popup extender and then use java-script to show/hide the modal pop-up on actual icon click. For example,

<asp:ModalPopupExtender runat="server" ID="MyPopup" ... />

<script type="text/javascript" />

function showPopup() {
  $find('<%= MyPopup.ClientID ').show();
}

function hidePopup() {
  $find('<%= MyPopup.ClientID ').hide();
}

</script>

Personally, I am not a fan of ajax control toolkit. For this requirement, I would have used jquery UI Dialog .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM