This is a migrated thread and some comments may be shown as answers.

Export To Excel and Close Window without Prompt

3 Answers 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 09 May 2013, 01:09 PM
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.

3 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 14 May 2013, 12:11 PM
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.
0
ArtiCut
Top achievements
Rank 1
answered on 06 Nov 2016, 10:23 AM

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?

0
Daniel
Telerik team
answered on 09 Nov 2016, 11:48 AM
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.
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
ArtiCut
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or