Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,

I am creating an Web application contains lot of reports to be generated. I am dynamically creating a "table" and adding "tr" and "td" based on the records from Database and appending it to String Builder and Finally assigning the string to InnerHTML of Div Tag.

I want to provide Exporting the Table to Excel for user and I am able to export the contents including CSS Style using the below code when it is an individual page. But the below code is not working when I go for Content Page(Having Master Page).
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.Charset = ""
GenerateEvalReport() ' Generating the Table here and assigning to DIV.InnerHTML
Response.AddHeader("content-disposition", "EvalReport.xls")
Response.ContentType = "application/vnd.ms-excel"
' Response.ContentType = "application/ms-excel" -- Tried this also. Not Working

Dim objRow As New HtmlTableRow
Dim objCell As New HtmlTableCell
objCell.Controls.Add(tblBody) ' 'tblBody'- Id of my Dynamic Table
objRow.Cells.Add(objCell)
table1.Rows.Add(objRow) ' Have one more Table as 'table1'
table1.RenderControl(oHTMLTextWrite)
Response.Write(oStringWriter.ToString())
Response.Flush()
Response.End()


I am getting two different Errors(since I have used the same code in 2 pages) when using Response.Write(oStringWriter.ToString())
1. Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed
2. Unable to evaluate Expression. Thread Aborted.

Can you please point me where I made mistake.

Thanks a lot.
Posted
Updated 7-Nov-11 14:36pm
v6

 
Share this answer
 
Comments
allav_arunlml 4-Nov-11 5:41am    
Thanks for you immediate response. I checked the links and they have dealt with either Dataset or Data Table. I don't have any like that rather than string Builder. I would like to add one more point is that the same code works in other page which don't have any master page, but not in page having master page. Is there any thing related to that?
 
Share this answer
 
Comments
allav_arunlml 4-Nov-11 5:44am    
Thanks Simple.V for your timely response. I checked the link and it seems they are exporting from data table but I am having HTML table which is already generated with multiple dataset and adequate CSS. Can't I export the whole outer Table("tblBody" in my case) to Excel when it is in Content Page?
I have Used Three Content Place Holders in Master Page and also Disabled the Viewstate in Content Page.
What I did is enable the Viewstate in Content Page and added Three asp:contents in Content Page. 1 for Head, 1 for AJAX related scripts and 1 for non AJAX related Scripts. Then the same above code works fine for me.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900