Hello All,

I have a Collapsible Panel Extender inside a datalist.I have a hyperlink inside the panel within the datalist. I want to have a modal popup on clicking the hyperlink inside the panel and I want the modal pop up to be populated with the data from the navigate URL property of the hyperlink. Is it possible to do this? If yes,please give your suggestions.


I am attaching my code,this is currently throwing an exception which I am guessing is because it is unable to find the hyperlink in the panel within the datalist :-

<asp:ToolkitScriptManager ID="ToolkitScriptManager_CollapsiblePanel" runat="server">
    </asp:ToolkitScriptManager>
     <asp:Datalist ID="Datalist_NewsItems" runat="server" Width="60%">

     <ItemTemplate>
    
      <table border="0" cellpadding="0" cellspacing="0" width="800">
       <tr>
       <td width="600">
          <asp:Panel ID="Panel2" runat="server">
            <asp:Image ID="Image1" runat="server" ImageUrl="~/images/plus.jpg" ></asp:Image>
            <%#Eval("Title").ToString()%>
    
           </asp:Panel>
   
        </td>
       </tr>
       
        <tr>
        <td colspan="3">
    <asp:Panel ID="Panel1" runat="server" BorderStyle= "Outset">
    <strong>Abstract:</strong>
     <asp:Label ID="Label_Abstract" runat="server" Text='<%#Eval("Abstract").ToString()%>'></asp:Label>
     <br />
     <asp:HyperLink ID="HyperLink_FullStory" runat="server" Text="Full Story" NavigateUrl='<%#Eval("LinkAddress")%>'></asp:HyperLink>
    </asp:Panel>
   
    <asp:CollapsiblePanelExtender ID="CollapsibleControl_Name" ExpandControlID="Panel2" runat="server" ImageControlID="Image1" ExpandedImage="~/images/minus.jpg" CollapsedImage="~/images/plus.jpg" ExpandDirection="Vertical" CollapseControlID="Panel2" Collapsed="true" EnableViewState="false" TargetControlID="Panel1"></asp:CollapsiblePanelExtender>
    </td>
   </tr>

    </table>
    </ItemTemplate>
     </asp:Datalist>
    <asp:Panel ID="news_details" CssClass="ModalPanel" runat="server">
    <p><strong><font size="6">Details Page</font></strong></p>
    </asp:Panel>
        <asp:ModalPopupExtender ID="PopupExtender" TargetControlID="HyperLink_FullStory" PopupControlID="news_details" BackgroundCssClass="modalBackground" runat="server"></asp:ModalPopupExtender>

Thanks.

Dani AI

Generated

Short answer: yes — but not the way the page is currently wired. The runtime error you’re seeing is the common symptom of assigning the ModalPopupExtender’s TargetControlID to a control inside a templated DataList item. The extender expects a page-level target (or to be created inside the same item template), so it cannot find the repeated HyperLink control by the simple ID you used. was right that calling Show() will display the popup, but first you need a valid trigger or to show it from code. (learn.microsoft.com)

Two reliable patterns:

  • Server-side (good when you want to pre-load or sanitize content). Put a single hidden button/label on the page and set that as ModalPopupExtender.TargetControlID. In the DataList use a LinkButton (CommandArgument = LinkAddress) and handle ItemCommand. Populate the popup panel (or set an iframe src) in the handler and call PopupExtender.Show(). This avoids trying to wire the extender to every repeated control and works nicely with UpdatePanel partial updates. (learn.microsoft.com)

Example server-side flow (short):

<!-- page-level hidden trigger and LinkButton in ItemTemplate -->
<!-- in ItemCommand: read e.CommandArgument, set popup content (or iframe.src) and call PopupExtender.Show() -->
  • Client-side (fast, no postback). Put an iframe or container inside the popup. Give the ModalPopupExtender a BehaviorID and, when the user clicks the per-item anchor (or a data-url attribute), set the iframe.src and call the client API ($find('yourBehaviorId').show()). This keeps the page responsive but watch framing restrictions. (ajaxtoolkit.net)

Caveats & troubleshooting: use e.Item.FindControl / ItemDataBound to find template controls server-side (FindControl on Page won’t work inside templates). If you use an iframe, external sites may block framing with X-Frame-Options or CSP frame-ancestors — test those URLs first. Also sanitize any server-fetched HTML to avoid XSS. (stackoverflow.com)

Checklist: replace the navigational HyperLink with a LinkButton or client-side anchor that prevents default navigation; give the extender a page-level target (or put one extender per item); choose iframe (full page) vs. AJAX fetch (HTML injection) based on security and layout needs.

Can someone please help me out here!

Hi

For modal pop up be populated with data from a URL .

You can put logic at anywhere

ModelPopup.Show()

and it will popup after this code.

For more detail check this link.

http://forums.asp.net/p/1582188/3989372.aspx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.