Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I call MyHandler from the client through ajax using mootoools
In Myhandler, I send some data back, that should be exported to excel in client.
The code in ProcessRequest in the MyHandler is following:
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.ContentType = "application/vnd.xls";
 
Response.Write("FirstName");
Response.Write(Environment.Newline);
Response.Write("Igor")"
Response.End();
 
When the response is returned to the client, no dialog is shown for asking to save the file. The server returns just xml. How to do that when the response is returned to client, the dialog will be shown and ask to save the attachment?
 
Thanks
Posted 5-Oct-10 7:27am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I don't know about doing this via ajax, but you can do this easily with a hidden iframe on your page:
 
page1.aspx:
 
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function test() {
            document.getElementById("ifr").src = "page2.aspx";
        }
    </script>
</head>
<body >
    <form id="form1" runat="server">
    <asp:Button ID="doit" runat="server" OnClientClick="test(); return false;" />
    <iframe id="ifr" style="display:none" />
    </form>
</body>
</html>
 

Page2.aspx:
 
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Page2.aspx.vb" Inherits="Page2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    </div>
    </form>
</body>
</html>
 

 

page2.aspx.vb:
 
Partial Class Page2
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.Clear()
        Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")
        Response.ContentType = "application/vnd.xls"
        Response.Write("FirstName")
        Response.Write(Environment.NewLine)
        Response.Write("Igor")
        Response.End()
    End Sub
End Class
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 457
1 OriginalGriff 430
2 Shai Vashdi 240
3 Emre Ataseven 165
4 Peter Leow 146
0 Sergey Alexandrovich Kryukov 8,944
1 OriginalGriff 5,280
2 Peter Leow 3,985
3 Maciej Los 3,535
4 Abhinav S 3,218


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 5 Oct 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid