Quantcast
Channel: AjaxControlToolkit Work Item Rss Feed
Viewing all articles
Browse latest Browse all 4356

Commented Unassigned: IE7/8 Cannot download file (when streamed to browser) [27494]

$
0
0
Since upgrading to the new AjaxControlToolkit version (July 2013 Release) streaming of Excel files to the browser has stopped working.

This worked perfectly on older versions of the AjaxControlToolkit (last version I used was 3.031106.0)

I'm basically writing the HTML of a GridView to Response as below;

```
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=myexcelsheet.xls")
Response.Charset = ""
Response.ContentType = "application/vnd.xls"

Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)

paycalc_GridView.RenderControl(htmlWrite)
Dim d As String = ""

Response.Write(stringWrite.ToString())
Response.End()

```
Comments: Ok, here's some code to get you started... It affects IE7 and IE8 and only when using SSL. I downloaded the June2013 release and it works! This is broken in the July2013 release. ``` <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="gridviewExport.aspx.vb" Inherits="testACTK_July2013.gridviewExport" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %> <!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"> <ajaxToolkit:ToolkitScriptManager runat="Server" EnablePartialRendering="true" ID="ToolkitScriptManager1" /> <div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:GridView ID="my_GridView" runat="server"> </asp:GridView> <br /> <asp:LinkButton ID="export_LinkButton" runat="server">Export</asp:LinkButton> </ContentTemplate> <Triggers> <asp:PostBackTrigger ControlID="export_LinkButton" /> </Triggers> </asp:UpdatePanel> </div> </form> </body> </html> ``` ``` Public Class gridviewExport Inherits System.Web.UI.Page Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) ' Confirms that an HtmlForm control is rendered for the specified ASP.NET ' server control at run time. */ End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then my_GridView.DataSource = GetSomeData() my_GridView.DataBind() End If End Sub Protected Function GetSomeData() As DataTable Dim dt_tble As New DataTable Dim dt_row As DataRow dt_tble = New System.Data.DataTable("students") dt_tble.Columns.Add("id", GetType(Integer)) dt_tble.Columns("id").AutoIncrement = True dt_tble.Columns("id").AutoIncrementSeed = 1 dt_tble.Columns.Add("studentID", GetType(String)).DefaultValue = "" dt_tble.Columns.Add("studentULN", GetType(String)).DefaultValue = "" For i As Integer = 0 To 24 dt_row = dt_tble.NewRow dt_row("studentID") = i + 100 dt_row("studentULN") = "ABC" & i + 100 dt_tble.Rows.Add(dt_row) Next Return dt_tble End Function Private Sub export_LinkButton_Click(sender As Object, e As System.EventArgs) Handles export_LinkButton.Click Response.Clear() Response.AddHeader("content-disposition", "attachment;filename=" & "myGridview" & ".xls") Response.Charset = "" Response.ContentType = "application/vnd.xls" Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter() Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite) Dim title As New Label my_GridView.RenderControl(htmlWrite) Dim myregex As New Regex("<(A|a)([ ]([a-zA-Z]+)=(""|')[^""\']+(""|'))*[^>]+>([^<]+)(</A>|</a>) ") '<(FONT|font)[^>]*>[^<]*(</FONT>|</font>) Dim d As String = "" d = Regex.Replace(stringWrite.ToString(), "<(A|a)([ ]([a-zA-Z]+)=(" & Chr(34) & "|')[^" & Chr(34) & "\']+(" & Chr(34) & "|'))*[^>]+>([^<]+)(</A>|</a>)", "$6") Response.Write(d.ToString()) Response.End() End Sub End Class ```

Viewing all articles
Browse latest Browse all 4356

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>