Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2211
Export To Excel using Ajax?
posted

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:

 //Export to be triggered by tab being clicked when it is already the active tab:

function uwt_Main_Click(oWebTab, oTab, oEvent) {

alert('In webtab click event');

//Add code to handle your event here.

//alert('in tab clicked event.');

var CurrentTab = oWebTab.getSelectedIndex();

//alert('oWebTab Index ' + CurrentTab);

var newTabClicked = oTab.getIndex();

//alert('oTab Index ' + newTabClicked);

if(CurrentTab == newTabClicked)

{

alert(
'Tab clicked is currently selected');if (oTab.Key == 'OverView')

{

alert('tab clicked is overview');

//alert('Export To Excel');

try

{

PageMethods.exportOverviewGrid_to_Excel(
null, OnCallexportOverviewGrid_to_ExcelSuccess, OnCallexportOverviewGrid_to_ExcelError, null);alert('page Method called without error');

form1.submit();

}

catch(Err)

{

alert(Err.description);

}

}

//alert('the tab selected is the tab clicked');

}

}

// -->

function OnCallexportOverviewGrid_to_ExcelSuccess(res, destCtrl)

{

}

// -->

function OnCallexportOverviewGrid_to_ExcelError(error,userContext,methodName)

{

if(error !== null)

{

alert(error.get_message());

}

}

Server Side:

<System.Web.Services.WebMethod()> _

Public Shared Sub exportOverviewGrid_to_Excel()

Dim myGridExporter As Infragistics.WebUI.UltraWebGrid.ExcelExport.UltraWebGridExcelExporter = New Infragistics.WebUI.UltraWebGrid.ExcelExport.UltraWebGridExcelExporter()

Dim myConn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("myConn").ToString)

Dim str_SQL As String = "dbo.spGet_Part_List"

Dim myCommand As SqlCommand = New SqlCommand(str_SQL, myConn)Dim ds As DataSet = New DataSet

myCommand.CommandType = CommandType.StoredProcedure

myConn.Open()

Dim myDA As SqlDataAdapter = New SqlDataAdapter(myCommand)

myDA.Fill(ds)

If myConn.State = ConnectionState.Open Then

myConn.Close()

End If

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,
"test")

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

Parents
  • 2211
    posted

    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.

    Pat

Reply Children
No Data