Hey everyone,
I am trying to export a dataset to Excel using javascript calls to the server using Ajax. Here is what I have so far:
Client Side:
function uwt_Main_Click(oWebTab, oTab, oEvent) {
//Add code to handle your event here.
//alert('in tab clicked event.');
//alert('oWebTab Index ' + CurrentTab);
//alert('oTab Index ' + newTabClicked);
{
alert('tab clicked is overview');
//alert('Export To Excel');
form1.submit();
}
alert(Err.description);
//alert('the tab selected is the tab clicked');
// -->
alert(error.get_message());
Server Side:
<System.Web.Services.WebMethod()> _
Dim myGridExporter As Infragistics.WebUI.UltraWebGrid.ExcelExport.UltraWebGridExcelExporter = New Infragistics.WebUI.UltraWebGrid.ExcelExport.UltraWebGridExcelExporter()
Dim str_SQL As String = "dbo.spGet_Part_List"
myCommand.CommandType = CommandType.StoredProcedure
myConn.Open()
myDA.Fill(ds)
If myConn.State = ConnectionState.Open Then
myConn.Close()
End If
myTempGrid.DataSource = ds
myTempGrid.DataBind()
myGridExporter.ExportMode = Infragistics.WebUI.UltraWebGrid.ExcelExport.ExportMode.Download
End Sub
I'm not getting any errors; I'm just not getting the download dialog box. I have Tried forcing a post back using the submit method to no avail.
Any ideas, TIA?
Pat
Update:
changed pagemethods call to:
PageMethods.exportOverviewGrid_to_Excel(OnCallexportOverviewGrid_to_ExcelSuccess, OnCallexportOverviewGrid_to_ExcelError, oWebTab);
getting response from server side code in form of error:
A circular reference was detected while serializing an object of type 'Infragistics.Excel.Workbook'.
******** UPDATE ***********
Circular reference was caused by trying to pass the generated workbook back to the client as the result of a function.
The problem is caused by the server side code.
When called with a normal postback I do not receive any errors, and I do not get an excel file. This is the same result as the AJAX call.
Thanks to anyone looking.
This did the Trick. I just need to push the file to the client.
Public Shared Function exportOverviewGrid_to_Excel() As Boolean
---- 'data ret. code ommited but same as above' ----
For Each Table As DataTable In ds.Tables()
'Create Column Headers
myWorksheet.Rows.Item(0).Cells.Item(colIndex).Value = Table.Columns.Item(colIndex).ColumnName
Next
For Each dr As DataRow In Table.Rows
rowIndex += 1
myRow.Cells.Item(colIndex).Value = dr.ItemArray(colIndex)
'Dim myTempGrid As Infragistics.WebUI.UltraWebGrid.UltraWebGrid = New Infragistics.WebUI.UltraWebGrid.UltraWebGrid()
'myTempGrid.DataSource = ds
'myTempGrid.DataBind()
'myGridExporter.ExportMode = Infragistics.WebUI.UltraWebGrid.ExcelExport.ExportMode.Download
'myGridExporter.Export(myTempGrid)
Return True
End Function