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:
<%@PageLanguage="C#"MasterPageFile="../../masterpages/umbracoPage.Master"AutoEventWireup="true"CodeBehind="packageCaseStudy.aspx.cs"Inherits="chilliis.eFM.Generator.WebExtensions.plugins.packageCaseStudy"%><%@RegisterNamespace="umbraco.uicontrols"Assembly="controls"TagPrefix="umb"%><%@RegisterNamespace="umbraco.controls"Assembly="umbraco"TagPrefix="UmbracoControls"%><asp:ContentID="Content"ContentPlaceHolderID="body"runat="server"><divid="typeDescription"class="createDescription"><imgsrc="/umbraco/plugins/eFMGenerator/images/zipped-folder-245x245.jpg"/><p>Do you want to download the case study?
</div><divid="zipProgress"style="display:none;"><p>Please wait, your case study is being zipped up.</p><umb:ProgressBarID="ProgBar"runat="server"/></div><divstyle="margin-right: 15px;"id="packageControls"><asp:Buttonrunat="server"Text="Download Package"ClientIDMode="Static"ID="DownloadBtn"/><em> or </em><aonclick="UmbClientMgr.closeModalWindow()"style="color: Blue; margin-left: 6px;"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
{
publicpartialclasspackageCaseStudy : System.Web.UI.Page
{
protectedvoid Page_Init(object sender, EventArgs e)
{
}
protectedvoid Page_Load(object sender, EventArgs e)
{
DownloadBtn.Click += newEventHandler(this.DownloadBtn_Click);
}
protectedvoid 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 = newZipFile())
{
// 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.");
}
}
}
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.");
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.
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.
Can someone help me please?
ASPX page that opens in modal window:
Code behind ASPX page that delivers the zip file:
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)?
Can anyone help? Does anyone know where I'm going wrong?
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.
My other mistake was that to stream the zip file to the user, I've changed the Content Type of the response:
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.
I've got the same problem in V6.1 but I am inheriting from UmbracoEnsuredPage.
is working on a reply...