[CLOSED] Export Button in a Window

  1. #1

    [CLOSED] Export Button in a Window

    Hi,

    I have a [Export to Excel] button in a window.

    protected void ExportToExcel(object sender, DirectEventArgs e)
    {                   
        MemoryStream stream = new MemoryStream();
        wb.SaveAs(stream);
        stream.Position = 0;
    
        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment; filename=" + myName);
        Response.ContentType = "application/vnd.ms-excel";
        Response.BinaryWrite(stream.ToArray());
        Response.End();
    }
    When I click on the Export button, it throws an exception "{success:false,message:"Blocked a frame with origin "https://xxx.com" from accessing a cross-origin frame."}" using Chrome. IE is working fine.

    Can you help me on this?
    Thank you.
    Last edited by fabricio.murta; Sep 22, 2017 at 10:18 PM. Reason: no feedback from the user in 7+ days
  2. #2
    Hello @bapas1!

    I'm afraid this is a browser limitation to avoid XSS attacks. A few days ago while trying some test cases I noticed this on chrome and then just switched the links to local addresses to avoid the browser limitation.

    See this stackoverflow thread for a good answer about what is that: SecurityError: Blocked a frame with origin from accessing a cross-origin frame

    I hope this helps!

    p.s.: Would you mind wrapping code between [code][/code] tags when you paste some on your posts? Makes it much better to read. I believe you did this in your past threads and just this one was left without it. We would really appreciate if you took your time to edit your post above and add the tags.
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hi,

    I have moved the Export button from window to a gridpanel.

    <ext:GridPanel runat="server" ID="gvUploadHistory" EnableTextSelection="true">
        <ColumnModel runat="server">
            <Columns>
                <ext:CommandColumn runat="server" Text="Action">
                    <Commands>
                        <ext:GridCommand Text="Export" CommandName="Export" Icon="PageExcel">
                            <ToolTip Text="Export Data Comparison" />
                        </ext:GridCommand>
                    </Commands>
                    <DirectEvents>
                        <Command OnEvent="ExportCommand">
                        </Command>
                    </DirectEvents>
                </ext:CommandColumn>
            </Columns>
        </ColumnModel>
    </ext:GridPanel>
    When I click on the Export button in the grid, it throws an exception "{success:false,message:"Blocked a frame with origin "https://xxx.com" from accessing a cross-origin frame."}" again using Chrome. IE is working fine.

    Is there any way I can do an export in the grid using Chrome?
    Thank you.
    Last edited by bapas1; Jul 24, 2017 at 3:47 AM.
  4. #4
    Hello @bapas1!

    The code snippets you provided do not help to determine the cause you are getting cross-origin complaints from chrome. But also, they don't add up, as you define a ExportToExcel function and calls a ExportCommand event.

    The best I can think of at the moment is pointing you to our example demonstrating how to export a whole grid panel to various format:
    - GridPanel > Miscelanneous > Export Data using Ajax

    If this does not help at all, please provide a runnable code sample according to our Guidelines on Posting new Topics, in particular, item 7B. With that we expect to be able to know how exactly you are trying to do the export and how, given that context, it should be done to avoid the cross-origin fix.

    At first, cross-origin issues shouldn't be arising if you are just calling code behind from the same server the pages are served, so the matter lies in what was not shared about the issue so far.

    Anyways, I really hope the export example pointed above helps you out! If not, let's try the test case approach.
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Hi,

    Click image for larger version. 

Name:	Upload Page.PNG 
Views:	93 
Size:	60.4 KB 
ID:	25031
    Refer to the attachment, when I upload a file, it will insert a record to the UploadHistory table.
    There will be some data checking and comparison.

    I would like to export the comparison data (by clicking the Export button). It throws an exception "{success:false,message:"Blocked a frame with origin "https://xxx.com" from accessing a cross-origin frame."}" using Chrome. IE is working fine.

                           <ext:GridPanel runat="server" ID="gvUploadHistory" EnableTextSelection="true">
                                <ColumnModel runat="server">
                                    <Columns>
                                        <ext:DateColumn runat="server" Text="Last Upload Date" DataIndex="CreatedDateTime" Format="dd-MMM-yyyy HH:mm" Width="150" Sortable="true">
                                            <Filter>
                                                <ext:DateFilter DataIndex="CreatedDateTime" Format="dd-MMM-yyyy HH:mm:ss" />
                                            </Filter>
                                        </ext:DateColumn>
                                        <ext:Column runat="server" Text="Uploaded By" DataIndex="CreatedBy" Width="150" Sortable="true">
                                            <Filter>
                                                <ext:StringFilter DataIndex="CreatedBy" />
                                            </Filter>
                                        </ext:Column>
                                        <ext:Column runat="server" Text="File Name" DataIndex="FileName" Width="400">
                                            <Filter>
                                                <ext:StringFilter DataIndex="FileName" />
                                            </Filter>
                                        </ext:Column>
                                        <ext:Column runat="server" Text="Title" DataIndex="Title" Flex="1" Width="400">
                                            <Filter>
                                                <ext:StringFilter DataIndex="Title" />
                                            </Filter>
                                        </ext:Column>
                                        <ext:Column runat="server" Text="Upload Status" DataIndex="UploadStatus" Width="150">
                                            <Filter>
                                                <ext:StringFilter DataIndex="UploadStatus" />
                                            </Filter>
                                        </ext:Column>
                                        <ext:CommandColumn runat="server" Width="200" Cls="ClsAction" Text="Action">
                                            <Commands>
                                                <ext:GridCommand Text="Download" CommandName="Download">
                                                    <ToolTip Text="Download" />
                                                </ext:GridCommand>
                                                <ext:GridCommand Text="View Data" CommandName="ViewData">
                                                    <ToolTip Text="View Data" />
                                                </ext:GridCommand>
                                                <ext:GridCommand Text="Export" CommandName="Export" Icon="PageExcel">
                                                    <ToolTip Text="Export Data Comparison" />
                                                </ext:GridCommand>
                                            </Commands>
                                            <DirectEvents>
                                                <Command OnEvent="DownloadCommand">
                                                    <ExtraParams>
                                                        <ext:Parameter Name="command" Value="command" Mode="Raw"></ext:Parameter>
                                                        <ext:Parameter Name="RowUploadRecId" Value="record.data.UploadRecId" Mode="Raw" />
                                                    </ExtraParams>
                                                </Command>
                                            </DirectEvents>
                                        </ext:CommandColumn>
                                    </Columns>
                                </ColumnModel>
                                <SelectionModel>
                                    <ext:RowSelectionModel runat="server" Mode="Single"></ext:RowSelectionModel>
                                </SelectionModel>
                                <Plugins>
                                    <ext:GridFilters runat="server" />
                                </Plugins>
                                <View>
                                    <ext:GridView runat="server" StripeRows="true" />
                                </View>
                                <BottomBar>
                                    <ext:PagingToolbar runat="server">
                                    </ext:PagingToolbar>
                                </BottomBar>
                                <MessageBusListeners>
                                    <ext:MessageBusListener Name="refresh1" Handler="reloadGrid();clearFilter();" />
                                </MessageBusListeners>
                                <TopBar>
                                    <ext:Toolbar runat="server">
                                        <Items>
                                            <ext:FileUploadField runat="server" ID="fFileUpload" Width="400" Icon="Attach" EmptyText="Select file to upload..." />
                                            <ext:Button runat="server" ID="btnUpload" Text="Upload File" Icon="DiskUpload">
                                                <Listeners>
                                                    <Click Handler="Ext.net.Mask.show({ msg : 'Data Uploading.. Please Wait..' }); DDUpload.ShowUploadConfirmation();" />
                                                </Listeners>
                                            </ext:Button>
                                        </Items>
                                    </ext:Toolbar>
                                </TopBar>
                            </ext:GridPanel>
    
    
    
    
            protected void DownloadCommand(object sender, DirectEventArgs e)
            {
                string commandName = e.ExtraParams["command"];
                string UploadRecId = e.ExtraParams["RowUploadRecId"];
    
                    switch (commandName)
                    {
                        case "Download":
                            //do something
                            break;
                        case "ViewData":
                            //do something
                            break;
                        case "Export":
                            ExportToExcel(UploadRecId);
                            break;
                    }
            }
    
            protected void ExportToExcel(string strUploadRecId)
            {                   
                MemoryStream stream = new MemoryStream();
                wb.SaveAs(stream);
                stream.Position = 0;
    
                Response.Clear();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", "attachment; filename=" + myName);
                Response.ContentType = "application/vnd.ms-excel";
                Response.BinaryWrite(stream.ToArray());
                Response.End();
            }
    Last edited by bapas1; Jul 25, 2017 at 8:52 AM.
  6. #6
    Hello @bapas1!

    Can't run your test case in our side. Please provide a runnable and simplified test case as per our guidelines:

    - Tips for creating simplified code samples
    - More Information Required
    - Forum Guidelines

    Hope you understand.
  7. #7
    hi fabricio.murta,

    we have a complex coding and i cannot just send you a portion of our code.
    I can give you access to the test web site (as it is hosted to public) and let you remote to my PC to see the entire source code.

    can i have your common email address?
    i will send you the credential and the web site.

    Please let me know your concern.
    We really need your help.

    Thanks
  8. #8
    Testing with the app is not going to be of help.

    You will need to configure your DirectEvent to use IsUpload="true".

    We will not be able to provide further assistance until a reproducible test case is provided. See Fabricio's comments above with tips on how to provide a simplified sample demonstrates how to reproduce the problem.
    Geoffrey McGill
    Founder

Similar Threads

  1. Replies: 2
    Last Post: Apr 04, 2014, 9:41 PM
  2. [CLOSED] close Ext.Net Window after export to excel
    By PriceRightHTML5team in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 04, 2013, 12:06 PM
  3. Replies: 4
    Last Post: Nov 06, 2012, 7:22 AM
  4. Replies: 7
    Last Post: Feb 09, 2012, 11:17 AM
  5. [CLOSED] Button event is not firing in parent window from popup window
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 14, 2011, 7:35 PM

Posting Permissions