Export to excel without Response.End () ?

Hi all,

Im having problems exporting a gridview to excel. Most of the solutions i found here and on other sites include altering the response  - this has a nasty side effect of generating the expetion discussed here:

http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx -

on AJAX enabled pages.

To avoid this exeption i popup a new page - that isnt  AJAX Enabled - and export the gridview there.

This isnt working very well because the Response.End() stops the page from fully loading and thus i can not close the popup - unacceptable in production.

Is there a way to export to excel without ending the Response? - alternatively is there a way to 'regain control ' of the Response in order to close the popup?

I have been stuck on this problem for a while now - any help would really be appreciated ( my previouse post on this subject is here:

http://forums.asp.net/t/1225275.aspx)

Thanks again :P

Yaniv

 

0
Yaniv
3/6/2008 11:54:01 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

6 Replies
1121 Views

Similar Articles

[PageSpeed] 54

hi,

i can't understand  exactly the problem you are facing, is it you wanted to export datagrid to excel with out having a popup window, which asks for the default filetype to save etc


Ramesh S
DELL,
Bangalore, Koramangala,India

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
0
rameshcrc
3/6/2008 12:09:09 PM
Hi and thanks for the quick reply :P
 
No, that pop up for save as and so on is fine.
The problem is i cant use export methods which alter the reponse on ajax enabled pages. is there an alternative to altering the reponse when exporting a gridview to excel.
 
What i've tried to do is popup a new window which isnt ajax enabled and export the gridveiw from there.

This isnt working very well because the Response.End() stops the page from fully loading and thus i can not close the new  popup - unacceptable in production. If there is no way to export without altering the response - is there a way i could 'regain' control in order to close the page after the Response.End has fired ?

Thank you very much again - if this isnt clear plaese tell me :P

0
Yaniv
3/6/2008 12:19:40 PM

hi,

i got to know exactly whats the problem you are facing, try using  

var oXmlHttp = createXMLHttp(); object in your javascript of which you are calling ajax page like

oXmlHttp.open("get", "GetData.aspx");

it might solve the problem , else let me know i shall post the solution in detail...


Ramesh S
DELL,
Bangalore, Koramangala,India

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
0
rameshcrc
3/6/2008 12:42:26 PM

Hi and thank you very much for the quick response again :P

Im sorry im quite a noob :P could you post a more detailed solution ? im not sure what you mean.

Please note i am using the ajax toolkit.

Heres my ImageButton syntax if thats what you mean

<asp:ImageButton ID="ImageButton2" PostBackUrl="~/Store/ExportDayView.aspx" ImageUrl="~/images/Images/office2007_icon_excel.jpg" OnClientClick="window.open('ExportDayView.aspx','', 'width=10,height=10');return false;"

runat="server" />

0
Yaniv
3/6/2008 12:51:06 PM

Hi

Please use below code

 

<%@ Page Language="VB" AutoEventWireup="false" EnableEventValidation ="false"   %>
  <%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Odbc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script language ="vbscript" runat ="server" >
    Public ConnStr As String = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=TaxPRo;uid=root;pwd=password;option=3"
    Public con As OdbcConnection = New OdbcConnection(ConnStr)
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Response.Clear()

        Response.Buffer = True
        
        Response.AddHeader("Content-Disposition", "attachment; filename=" & TextBox1.Text & ".xls")

        Response.ContentType = "application/vnd.ms-excel"

        Dim writer As New System.IO.StringWriter()

        Dim html As New System.Web.UI.HtmlTextWriter(writer)

        GridView1.RenderControl(html)

        Response.Write(writer)

        Response.End()
    End Sub
    
    Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
    End Sub


    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

       
      
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
      
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim cmdsave2 As OdbcCommand = New OdbcCommand("select * from " & TextBox1.Text & "", con)
       
        con.Open()
        GridView1.DataSource = cmdsave2.ExecuteReader
        GridView1.DataBind()
        con.Close()
    End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1"  runat="server" Style="z-index: 100; left: 185px; position: absolute;
            top: 188px" AutoGenerateColumns="true" Width="310px">
     </asp:GridView>
        <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Style="z-index: 105;
            left: 443px; position: absolute; top: 92px" Text="Go....." Width="46px" />
           
       
       
        <asp:Button ID="Button1" runat="server" Style="z-index: 103; left: 506px; position: absolute;
            top: 92px" Text="Export" Width="100px" />
        <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 104; left: 264px; position: absolute;
            top: 92px">File name here</asp:TextBox>
          <br />
        <br />
        <br />
        <br />
                             Enter
        the Table name here:</div>
    </form>
</body>
</html>
  
Thanks
~Avinash desai~
Software Developer
Bangalore

Please remember to click "Mark as Answer" on this post if it helped you.
0
Avinash
3/6/2008 1:05:50 PM

Hi Avinash and thank you for your replays.

Im intrested in any solution to export to excel without using response.End as this finishes my page processing pre - maturly :P

 

0
Yaniv
3/11/2008 12:57:03 PM
Reply:

Similar Artilces:

Exporting to Excel in Crystal Reports .NET
sir,   I want to export Crystal report to Excel and the following is the code i wrote in the button click.ReportDocument rptExcel = new ReportDocument() ;string strExportFile = "C:/Session_SessionID.xls" ;rptExcel = new RptJobOrderRecap();//report namerptExcel.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile ;rptExcel.ExportOptions.ExportFormatType = ExportFormatType.Excel;ExcelFormatOptions objExcelOptions = new ExcelFormatOptions();objExcelOptions.ExcelUseConstantColumnWidth = false ;rptExcel.ExportOptions.FormatOptions = objExcelOptions ;DiskFileDestinationOp...

Export to excel without third party tools and without Excel on the Application Server.
I need to export a stored procedure in SQL Server to Excel. The stored procedure has two parameters. I need to Export to excel without third party tools and without Excel on the Application Server. Whats the easiest and best way?   p Unfortunately, this is again a link to another forum www.universalthread.com where this topic was discussed and several solutions provided. <B>Re: Create an Excel file (xls)</B> Thread #1304564 Message #1304876 I don't want to copy and paste code, you may want to check this yourself, but you have to become a member of the site in...

GridView control exporting to Excel in Net 2.0
Well, I did my homework and found 33,868 references to issues with the gridview control and Excel, none of which were close to whats happening with my app. I have a Gridview control on my VB.NET main page and when I right click on it the popup allows me to export to Excel just fine..5-6 columns, less than 100 rows..when I do the same on another page I get an Excel error popup : "This web query returned no data.."..both grids have a (Select) button in the 1st column. The one that works is simply that...the one that doesn't has the Button.Text defined as something e...

plzzz hElp -- Any alternative way to export datagrid to excel without response.write() ???help--
 hii evry1.,         since i hav a updatepanel in my page..im havng prblmz with response.write()....can any1 tel me an alternative way to export the data from datagridview cntrl to Excel with out Response.Write() ????? OR ELSE IS IT POSBL TO LAUNCH THE EXCEL IN A NEW BROWSER SO THAT I CAN ESCAPE THE UPDATEPANEL'S PROBLM?IF SO WATS THE CODE TO LAUNCH A NEW BROWSER TO LOAD THE EXCEL WITH "SAVE AS " DIALOG BOX ??? help me with a sampl code..! thnxxx..    Hi Softy@High , If you use asp.net.ajax on your p...

Export To Excel with formatted Text without installing excel on the server
I have the following export function to export data from datatable to excel on the client vai web browser and it works fine but I cannot add any text decoration to the strings. For example, in the code below, the first bolded section name "Header" i am trying to give the lable control with some text and color information but when i write lable with response.write it give me this "System.Web.UI.WebControls.Label" in the cell but the rest works, I need to find a way to put text decoration on the excel programmatically without having to install excel on the server....

Excel Export Control Showing Blank Worksheet in Excel 2003
I have a custom control (C#) that will take any datagrid, htmltable, or repeater and display it as a downloadable Excel document.  It currently works great in Office 97, but we are gradually rolling out Office 2003 and it seems to show a blank worksheet. Here is the code I am using for the control: using System;using System.Data;using System.Drawing;using System.Web;using System.IO;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;using System.ComponentModel;namespace MainWeb.CustomWebControls { public class ExcelExport : WebControl { protected ...

How to add the data present in the controls to a table control without any database involvement.
Hi All,i am four controls where i will write the text and once i click the add button those should get added to the table .i want 6 columns fixed in the table and rows as many as required.i tried doing that taking a table server control and able to load the table.but the problem is whenver i am adding a new row the old one is gfetting overwritten by this and at the end i am getting only one row.  System.Web.UI.WebControls.Table t1 = new System.Web.UI.WebControls.Table();  i have declared the below one global TableRow tr; TableCell tc1; TableCell tc2; TableCell tc...

Export to excel control
hi frnds, I am trying to achieve Export to Excel control with .net framework 2.0. I could find lots of samples on web for that. But what I need is a User or custom control with button to do this functionality. The control available are only for 1.1 and other samples dont work as controls. Now I tried using one of the sample here[^] as control. But I am facing issue with VerifyRenderingInServerForm which is not available in a user control. Any suggestions?? Any tried this before??Thanks,Geek Which data u r going to export.? If u have a GridView and need to export the data , Use...

try catch finally / response.redirect / response.end flow control question
Hi Guys, Can any one tell me if the finally block would be executed in the following example (assuming that dbReader.read() returned false because no records were found).   Many Thanks! DanielTry dbCon = New SqlConnection(myconnectionstring) dbCon.Open() dbCom = dbCon.CreateCommand() strSQL + "SELECT * FROM bookings WHERE ID &gt; 9000" dbCom.CommandText = strSQL dbReader = dbCom.ExecuteReader() If dbReader.Read() Then 'init fields Else Response.Redirect("main.aspx") End if Finally dbReader.clo...

How to show the report exporting date only in the exported PDF/Excel file (ReportViewer Control)?
Hello everyone, Our customer wants to display the exporting date only in the exported file when exports a report to PDF/Excel (we are using ReportViewer Control in ASP.NET). Can anybody tell me how to achieve this? Thanks a lot. I mean I have a textbox which will show date info, and you just want show this textbox for excel/pdf render in asp2.0. So you want it to hide when in the GUI but show up on export?  Yay for figuring things out.(@.@) Yes, you are right! Do you have any idea on this? And could I add the page navigation on the report footer? How?  Thanks ...

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

Export To Excel Excel
Do we have any facility to export grid data in Excel with using Report Tool. Just a question, Will Response.contenet Type will work here Thanks, private void btnExportToExcel_Click(object sender,System.EventArgs e) { ExportToExcel("Report.xls",DataGrid1); } private void ExportToExcel(string strFileName,DataGrid dg) { Response.Clear(); Response.Buffer = true; Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("content-disposition", "attachment;filename=" + strFileName); Response.Charset = ""; this.EnableVi...

Exporting in Excel without cells or excel columns merging for one column of data table(need sorting, data filters perfectly)
 Hi,   I have an issue with the excel exporting of the report using ssrs.  I am using only the body section for exporting to excel.  Here in the body i have an Image, Textbox(for Title), textbox2(for dates from,to) and below it i have a table having the columns used for showing the data.  The report gets generated but when i exported to excel, All the columns and rows in the excels sheets come close and its like there is no uniformity.  Few columsn of excel are covered under a single columsn of the data table.  So its making users feel uncomfortab...

XLSX export without Excel?
I am working in Delphi 5 (yes, you read that correctly, not XE5, but 5). I need to allow customers to export contents of dataset in our system to XLSX files without the need for Excel being installed. I am open to free or commercial solutions, as long as they work. So far, I have tested SMExport from Scalabium Software and am waiting for a reply from Mike about some formatting questions I had. While I am waiting, I would like to explore other options. So, what options ARE there? Any insight would be greatly appreciated. Thanks. Rich Rich Ackerson wrote: > I nee...

Web resources about - Export to excel without Response.End () ? - asp.net.presentation-controls

Responses to the Ebola virus epidemic in West Africa - Wikipedia, the free encyclopedia
Organizations from around the world have responded to help stop the ongoing Ebola virus epidemic in West Africa . In July 2014, the World Health ...

Kohli's sledge response goes viral
He may have hit a run-a-ball 117, but it was Indian vice-captain Virat Kohli's response to a sledge by Australian bowler James Faulkner that ...

Tactical response group sent in to Kenwick domestic amid gun fears
FIREARM fears prompted police to call in the tactical response group during a domestic incident in one of Perth’s southeastern suburbs.

Australia v India: Virat Kohli's perfect response to James Faulkner sledge
... Virat Kohli made the history books when he registered his 24th century and 7000 runs in ODIs at the MCG on Sunday but it was his perfect response ...

Kohli's sledge response goes viral
He may have hit a run-a-ball 117, but it was Indian vice-captain Virat Kohli's response to a sledge by Australian bowler James Faulkner that ...

René Angélil's death draws strong response from fans, friends
... death has left friends and fans saddened and expressing their condolences to the family of international superstar of Céline Dion. Responses ...

Zulily's Response To Customer Wanting To Return Coat Goes Viral
... returning items is nothing new and the fact most companies will do an exchange or refund isn't either. But one online retail website's response ...

TAKE A HIKE, NIKKI: Haley Attacks the Conservative Base in Response to State of the Union Speech
By Sara Noble What do you think about this? Barack Obama has ruled the nation like a dictator with no regard for the Constitution. He is responsible ...

Does The World Need a Bluetooth-Enabled Pregnancy Test? First Response Thinks So
... tech during the explosion of smart gadgets and the Internet of Things, but less so when it comes to feminine hygiene and pregnancy. First Response, ...

eMotorWerks Now Involved In Demand Response With California Utilities
Originally published on EV Obsession. All 3 major investor-owned utility companies in California have awarded demand response contracts to the ...

Resources last updated: 1/19/2016 12:37:17 PM