Export To Excel and Close Window without Prompt

4 posts, 0 answers
  1. Mike
    Mike avatar
    338 posts
    Member since:
    Jun 2008

    Posted 09 May 2013 Link to this post

    I have a webpage that has a RadGrid on it and when the page is opened I create an excel attachment using memory stream and send it in an email, then close the window. 

    This all works great, I even don't show a prompt to close the window. 

    I firmly beleive it has to do with this setting, OpenInNewWindow.  But when I do that
    RadGrid Grid1 = (RadGrid)Page.Master.FindControl("Main").FindControl("RadGrid1");
    Grid1.ExportSettings.OpenInNewWindow = true;


    However, at the bottom of the page there is a dialog to Open, Save or Cancel. 
    How can I disable this prompt? 

    I have attached images from IE 9 and FireFox 11.

    One trick I have seen and it works is to simply create a new html page and have a Redirect to that page at the end of the export that only has a window.close() in the JavaScript.
  2. Kostadin
    Admin
    Kostadin avatar
    1709 posts

    Posted 14 May 2013 Link to this post

    Hi Michael,

    Another possible solution is to redirect to the same page. The following code snippet demonstrates the usage of FileStream and after it finished the page is reloaded again.
    protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
    {
        string path = Server.MapPath("~/MyFile.xls");
        using (FileStream fs = File.Create(path))
        {
            Byte[] info = System.Text.Encoding.Unicode.GetBytes(e.ExportOutput);
            fs.Write(info, 0, info.Length);
        }
        Response.Redirect(Request.Url.ToString());
    }


    All the best,
    Kostadin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. ArtiCut
    ArtiCut avatar
    5 posts
    Member since:
    Nov 2016

    Posted 06 Nov in reply to Kostadin Link to this post

    The command  " Response.Redirect(Request.Url.ToString());" redirect to the page,

    but the data at the radGrid is empty - the parameters at the page not saved. It's a problem...

     

    How can I come back to the page, but the parameters and the data should remain?

    or How  can I export to excel and prevent the following message to appear without redirect to the page?

  5. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 09 Nov Link to this post

    Hello,

    Please refer to my answer in the following thread:
    Export to pdf and save programmatically

    As to the other question, I'm not sure what parameters are lost in your code, but if you provide more details I may be able to help.

    Regards,
    Daniel
    Telerik by Progress
    Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Back to Top