Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ian Robinson 79 posts 143 karma points
    Mar 13, 2012 @ 16:51
    Ian Robinson
    0

    Unable to close modal window or show speech bubble using ClientTools

    I'm modifying the content tree in Umbraco 4.7.1.1 so that when the user right-clicks on a particular node, I open a modal window asking the user if they are sure they want to download the content (known as a Case Study).

    If the user clicks on the "Download" button, I zip up a folder and it's contents on the web server and then stream it to the user, which causes a standard open/save web browser dialog box to pop up.

    This is all working well, but I would like to close the Umbraco modal window and display a speech bubble, informing the user that the file has been downloaded, but the two calls to BasePage.Current.ClientTools are doing nothing.  No error is being thrown but the modal window isn't being closed and no speech bubble appears.

                BasePage.Current.ClientTools.CloseModalWindow();
                BasePage.Current.ClientTools.ShowSpeechBubble(BasePage.speechBubbleIcon.save, "Package Created""The case study package has been created.");

    Can someone help me please?

    ASPX page that opens in modal window:

    <%@ Page Language="C#" MasterPageFile="../../masterpages/umbracoPage.Master" AutoEventWireup="true" CodeBehind="packageCaseStudy.aspx.cs" Inherits="chilliis.eFM.Generator.WebExtensions.plugins.packageCaseStudy" %>
    <%@ Register Namespace="umbraco.uicontrols" Assembly="controls" TagPrefix="umb" %>
    <%@ Register Namespace="umbraco.controls" Assembly="umbraco"  TagPrefix="UmbracoControls" %>
    
    <asp:Content ID="Content" ContentPlaceHolderID="body" runat="server">
    
            <div id="typeDescription" class="createDescription">
                <img src="/umbraco/plugins/eFMGenerator/images/zipped-folder-245x245.jpg" />
                <p>Do you want to download the case study?
    
            </div>
    
            <div id="zipProgress" style="display:none;">
                <p>Please wait, your case study is being zipped up.</p>
                <umb:ProgressBar ID="ProgBar" runat="server" />
                </div>
    
            <div style="margin-right15px;" id="packageControls">
                     <asp:Button runat="server" Text="Download Package" ClientIDMode="Static" ID="DownloadBtn" />
                    <em> or </em>
                    <a onclick="UmbClientMgr.closeModalWindow()" style="colorBluemargin-left6px;" href="#">Cancel</a>
                
            </div>
            
    
    
            <script>
    
                $(document).ready(function () {
    
                    $("#DownloadBtn").click(function () {
    
                        $("#packageControls").fadeOut('slow'function () {
                            $(this).remove();
                            $("#zipProgress").fadeIn('slow');
                        });
                    });
    
                });
    
            </script>
    
    </asp:Content>

    Code behind ASPX page that delivers the zip file:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ionic.Zip;
    using System.IO;
    using System.Text;
    using umbraco.BasePages;
    
    namespace chilliis.eFM.Generator.WebExtensions.plugins
    {
        
        public partial class packageCaseStudy : System.Web.UI.Page
        {
            protected void Page_Init(object sender, EventArgs e)
            {
                
            }
            protected void Page_Load(object sender, EventArgs e)
            {
                
                DownloadBtn.Click += new EventHandler(this.DownloadBtn_Click);
    
            }
    
            protected void DownloadBtn_Click(object sender, EventArgs e)
            {
                
                var caseStudyId = 0;
    
                int.TryParse(umbraco.helper.Request("id"), out caseStudyId);
    
                var packageFileName = String.Format("CaseStudy_" + caseStudyId + ".zip");
                Response.ContentType = "application/zip";
                Response.AddHeader("Content-Disposition""filename=" + packageFileName);
    
                string path = Directory.GetCurrentDirectory();
    
                using (var zip = new ZipFile())
                {
                    // zip up standard player files
                    zip.AddDirectory(HttpContext.Current.Request.PhysicalApplicationPath + @"\umbraco\plugins\eFMGenerator\Player");
    
                    // create ims manifest file
    
                    // Add the README.txt file to the ZIP (STEP 3)
                    //zip.AddEntry("README.txt", "yo ian", Encoding.ASCII);
                    zip.Save(Response.OutputStream);
                }
    
                BasePage.Current.ClientTools.CloseModalWindow();
                BasePage.Current.ClientTools.ShowSpeechBubble(BasePage.speechBubbleIcon.save, "Package Created""The case study package has been created.");
                
            }
        }
    }
  • Ian Robinson 79 posts 143 karma points
    Mar 13, 2012 @ 21:28
    Ian Robinson
    0

    OK, it is throwing an error, but I didn't pick up on it before.

     When the first ClientTools method is called "CloseModalWindow()" the code throws the exception - "System.NullReferenceException: Object reference not set to an instance of an object.". The BasePage is populated but the Current object is null.

    Am I missing a reference somewhere, or inheriting from the wrong page type perhaps (System.Web.UI.Page)?

                BasePage.Current.ClientTools.CloseModalWindow();
                BasePage.Current.ClientTools.ShowSpeechBubble(BasePage.speechBubbleIcon.save, "Package Created""The case study package has been created.");
  • Ian Robinson 79 posts 143 karma points
    Mar 14, 2012 @ 13:18
    Ian Robinson
    0

    Can anyone help?  Does anyone know where I'm going wrong?

  • Ian Robinson 79 posts 143 karma points
    Mar 15, 2012 @ 12:00
    Ian Robinson
    2

    I think I've found the issue.

    To start with I need to inherit from UmbracoEnsuredPage and not just Page.  This ensures that "BasePage.Current" is not null.

     

    public partial class packageCaseStudy : umbraco.BasePages.UmbracoEnsuredPage
    

     

    My other mistake was that to stream the zip file to the user, I've changed the Content Type of the response:

         Response.ContentType="application/zip";
        
    Response.AddHeader("Content-Disposition","filename="+ packageFileName);
     

    However, this means the call to close the window and display the speech bubble won't work.  If I comment out the zip part of the code, both ClientTools method calls work.

    Now I understand why the methods aren't running properly I can work on a better solution, that allows me to close the modal and allow the user to download the zip.

     

  • Matt Taylor 873 posts 2086 karma points
    Jul 24, 2014 @ 16:09
    Matt Taylor
    0

    I've got the same problem in V6.1 but I am inheriting from UmbracoEnsuredPage.

Please Sign in or register to post replies

Write your reply to:

Draft