Hello Fabricio,
Here is what I have done until now and the error I receive:
Error
Uncaught TypeError: Cannot read property 'load' of null
ToExcel.ascx:ln29
ToExcel.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ToExcel.ascx.cs" Inherits="ICDMSAdmin.Modules.ToExcel" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script src="Scripts/scriptlibrary.js"></script>
<ext:DesktopModuleProxy runat="server">
<Module ModuleID="toexcel">
<Shortcut Name="Export DB To Excel" IconCls="x-ToExcel-shortcut" X="50" Y="560" TextCls="x-long-label" >
</Shortcut>
<Window>
<ext:Window ID="WndwToExcel" runat="server"
Maximizable="false"
CloseAction="Destroy"
Layout="FitLayout"
Width="400"
Height="200"
Resizable="false"
BodyStyle="background-color: white; padding: 50px;"
Title="Export DB To Excel"
AutoScroll="true"
ButtonAlign="Center">
<Defaults>
<ext:Parameter Name="margin" Value="0 5 0 0" Mode="Value" />
</Defaults>
<Items>
<ext:Button ID="btnExport" runat="server" Text="Export to Excel" >
<Listeners>
<Click Handler="#{WndwToExcel}.load('\\Pages\\WebForm1.aspx');" />
</Listeners>
</ext:Button>
</Items>
</ext:Window>
</Window>
</Module>
</ext:DesktopModuleProxy>
ToExcel.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading.Tasks;
using Ext.Net;
using ClosedXML;
using System.IO;
using System.Data.SqlClient;
using System.Data;
namespace ICDMSAdmin.Modules
{
public partial class ToExcel : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
}
}
}
}
WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ICDMSAdmin.Pages.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server" />
<ext:FormPanel runat="server" Height="500">
<LayoutConfig>
<ext:HBoxLayoutConfig Align="Stretch" Padding="0" />
</LayoutConfig>
</ext:FormPanel>
</form>
</body>
</html>
WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading.Tasks;
using Ext.Net;
using ClosedXML;
using System.IO;
using System.Data.SqlClient;
using System.Data;
namespace ICDMSAdmin.Pages
{
public partial class WebForm1 : System.Web.UI.Page
{
public int ctid = 1058;
protected void Page_Load(object sender, EventArgs e)
{
if (ctid > 0)
{
SqlConnection sqlConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
SqlCommand command = new SqlCommand("GetCRFDataForAnalysis", sqlConnection);
command.CommandType = System.Data.CommandType.StoredProcedure;
command.CommandTimeout = 0; //infinite waiting time
command.Parameters.AddWithValue("@Ctid", ctid);
command.Parameters.AddWithValue("@SId", DBNull.Value);
command.Parameters.AddWithValue("@PId", DBNull.Value);
SqlDataAdapter sda = new SqlDataAdapter();
command.Connection = sqlConnection;
sda.SelectCommand = command;
DataSet ds = new DataSet();
sda.Fill(ds);
ds.Tables[0].TableName = "Database";
ds.Tables[1].TableName = "DBIndex";
DAL.DataContext dc = new DAL.DataContext();
var SelTrial = (from i in dc.CTs
where i.id == ctid
select i.Name).FirstOrDefault();
ClosedXML.Excel.XLWorkbook wb = new ClosedXML.Excel.XLWorkbook();
foreach (DataTable dt in ds.Tables)
{
wb.Worksheets.Add(dt);
}
string fname = "attachment;filename=\"Export:";
string ctname = SelTrial.ToString();
string ending = ".xlsx\"";
HttpResponse httpResponse = Response;
httpResponse.Clear();
httpResponse.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
//Provide you file name here
httpResponse.AddHeader("content-disposition", fname + ctname + ending);
// Flush the workbook to the Response.OutputStream
using (MemoryStream memoryStream = new MemoryStream())
{
wb.SaveAs(memoryStream);
memoryStream.WriteTo(httpResponse.OutputStream);
memoryStream.Close();
}
httpResponse.End();
}
else
{
X.Msg.Alert("Warning", "Please select a Study first").Show();
}
}
}
}