PDA

View Full Version : [CLOSED] Excel not generated by Direct Event



Tarun_Chand
Apr 09, 2013, 11:02 AM
Hi Team,

I am trying to generate a Excel download by a Direct Event button click defined as below -

============== aspx code ===================


<ext:Button ID="extBtn1" runat="server" Text="ToExcel-2">
<DirectEvents>
<Click OnEvent="ToExcel">
<EventMask ShowMask="true" />
</Click>
</DirectEvents>
</ext:Button>


with the event method defined as below -

============== C# ======================


protected void ToExcel(object sender, EventArgs e)
{

XElement eml = new XElement("Records",
new XElement("Record",
new XElement("SiteName"),
new XElement("TotalInstallCost"),
new XElement("TotalMonthlyCost","2000")
)
);


XmlDocument xmlDoc = new XmlDocument();

using (System.Xml.XmlReader xmlReader = eml.CreateReader())
{

xmlDoc.Load(xmlReader);

}

XmlNode xmlNode = xmlDoc; //.DocumentElement;

this.Response.Clear();
this.Response.ContentType = "application/vnd.ms-excel";
this.Response.AddHeader("Content-Disposition", "attachment; filename=submittedData.xls");
XslCompiledTransform xtExcel = new XslCompiledTransform();
xtExcel.Load(Server.MapPath("Excel.xslt"));
xtExcel.Transform(xmlNode, null, this.Response.OutputStream);
HttpContext.Current.ApplicationInstance.CompleteRe quest();
this.Response.Flush();
this.Response.Close();
//this.Response.End();
}


However the method does not generate the Excel report and seems to diffuse the output stream, with no error or output to the user screen.

Please advice.

Thanks

Daniil
Apr 09, 2013, 12:27 PM
Hi Tarun,

You should, at least, set up IsUpload to true.

<Click OnEvent="ToExcel" IsUpload="true">

Also EventMask doesn't work with AJAX downloading, because it doesn't fire any event after downloading. So, no way to determine when hide a mask.

The following can help with some scenarios.
http://forums.ext.net/showthread.php?19430#post83757