Cannot read property 'documentElement' of null

  1. #1

    Cannot read property 'documentElement' of null

    Hello,

    I am having an issue exporting a filtered gridview to excel using 3.1, VB.net with asp.net MVC. I've done many other export to excel operations before in this exact framework, and have never run into this issue for them. Here is my setup:

    aspx GridView and Store definition:
                               
    <ext:GridPanel ID="gpMarginMatrix" 
        runat="server" 
        MaxHeight="500" 
        autoscroll="true" 
        Width ="974"
        EnableViewState ="true">
        <Store>
            <ext:Store ID="dsMarginMatrix" 
                runat="server" 
                RemoteSort="true">
                <Proxy>
                    <ext:AjaxProxy Url="/Data/MarginMatrixDataNew/" Timeout="1200000">
                        <ActionMethods Read="POST" />
                        <Reader>
                            <ext:JsonReader Root="data" IDProperty="mxmid" SuccessProperty="Success" MessageProperty="Message" />
                        </Reader>
                        <Writer>
                            <ext:JsonWriter Root="data" />
                        </Writer>
                        <Listeners>
                            <Exception Handler="Ext.MessageBox.alert('Load failed', response.statusText);" />
                        </Listeners>
                    </ext:AjaxProxy>
                </Proxy>

    Export To excel button code:
    <ext:Button ID="btnExcel" runat="server" Text="To Excel" Icon="PageExcel">
        <Listeners>
             <Click Handler="
                                     Ext.net.DirectMethod.request({
                                         url : '/Data/ExportMginMtrxToExcel/',
                                         params : { 
                                             data :  Ext.encode(#{gpMarginMatrix}.getRowsValues({ visibleOnly:true }))
                                         } 
                                     });
             " />
        </Listeners>
    </ext:Button>

    Export to Excel Code in Controller:
            Public Function ExportMginMtrxToExcel(ByVal data As String) As ActionResult
                Dim filename As String = "MatrixMargins" + DateTime.Now().ToString()
                'Dim ds = Ext.Net.JSON.Serialize(data)
                Dim submitData As New Ext.Net.SubmitHandler(data)
                Dim xml As XmlNode = submitData.Xml
    
                Dim sb As New StringBuilder
                Dim writer As Global.System.Xml.XmlWriter = Global.System.Xml.XmlWriter.Create(sb)
    
                Dim xt As New XslCompiledTransform
                xt.Load(Server.MapPath("/Content/xsl/Excel.xsl"))
                xt.Transform(xml, writer)
    
                Dim result As FileContentResult = Nothing
                result = New FileContentResult(Encoding.UTF8.GetBytes(sb.ToString()), "application/vnd.ms-excel")
                result.FileDownloadName = filename + ".xls"
    
                Return result
    
            End Function


    The String that is passed back to the controller is a JSON string:
     "[{"MarGroupID":1,"Profile":"High","CZ":"HZ","Term":6,"FMonth":"1","Margin":"0","HC_Med_Mar":"0","HC_Small_Mar":"0","mxmid":481}]"
    however i get this error as an EXT popup afterwards:
    Status Code: 200
    Status Text: BADRESPONSE: Cannot read property 'documentElement' of null
    There are no errors stepping through the code, and everything appears to be running without error. I read in another thread that you told someone to add in <AjaxEventConfig IsUpload="true" /> however i tried following this example but this tag no longer exists in 3.1?

    Thank you for any help you can give.
    Last edited by geoffrey.mcgill; Apr 26, 2016 at 3:22 PM.
  2. #2
    Hoping that by replying to your post from 4 months ago, it will refresh it for the devs and maybe they'll reply to it. I am having the same issue as this: no errors, except the error popup after i click the button to get the excel document. The difference between your code and mine though is that i'm not trying to get the results of a Store to export to excel, rather i just have a button that gets the results of a stored proc and immediately exports to excel:

                Dim batchID as integer = 34
                Dim query = Nothing
                Dim filename As String = "test"
    
                DBIEnergyContext.CommandTimeout = 500
                query = DBIEnergyContext.sp_ReliantSCM_Details(batchID).ToList
    
                Try
                    Dim xml As XmlNode
                    Dim ds = Ext.Net.JSON.Serialize(query)
                    Dim pattern As String = "T..:..:.."
                    ds = Regex.Replace(ds, pattern, "")
                    Dim submitData As New Ext.Net.SubmitHandler(ds)
                    xml = submitData.Xml
    
                    Dim sb As New StringBuilder
                    Dim writer As Global.System.Xml.XmlWriter = Global.System.Xml.XmlWriter.Create(sb)
                    Dim xt As New XslCompiledTransform
                    xt.Load(Server.MapPath("/Content/xsl/Excel.xsl"))
                    xt.Transform(xml, writer)
    
                    Dim result1 As FileContentResult = Nothing
                    result1 = New FileContentResult(Encoding.UTF8.GetBytes(sb.ToString()), "application/vnd.ms-excel")
                    result1.FileDownloadName = filename + ".xls"
    
                    query = Nothing
                    Return result1
                Catch ex As System.Exception
                    result.ErrorMessage = ex.Message.ToString
                    query = Nothing
                    Return result
                End Try
    This returns no error while debugging, yet gives me a "Cannot read property 'documentElement' of null" error.

Similar Threads

  1. Replies: 1
    Last Post: Dec 15, 2015, 2:18 PM
  2. Replies: 2
    Last Post: Aug 13, 2014, 3:01 AM
  3. [CLOSED] Uncaught TypeError: Cannot read property 'items' of null
    By tobros in forum 2.x Legacy Premium Help
    Replies: 10
    Last Post: Nov 20, 2013, 11:45 AM
  4. Replies: 1
    Last Post: Nov 14, 2013, 9:44 PM
  5. Uncaught TypeError: Cannot read property 'items' of null
    By FlavioSilveira in forum 2.x Help
    Replies: 6
    Last Post: Sep 20, 2013, 7:37 PM

Tags for this Thread

Posting Permissions