Server.Transfer Method Problem

thussain

Newcomer
Joined
Jul 23, 2004
Messages
2
I use the following article to write code which let me pass data from one from to another

http://www.aspalliance.com/das/passingdata.aspx

I am writing a report using Microsoft Datagrid control and also giving user ability to exprot into Excel both of these button exist in criteria form of the application.

I use First form to collect all the Criteria to run the report and use second form to display it. My second form has a datagrid. On the first form when user use Run it show data in the teh second form data grid control and if they select Excel Export the datagrid show it in the Excel using following Code.

My problem is I am using server.transfer("secondform") method which when finish running if I use browse back button to go back to firstform it loss all the user selction criteria.
Second issue I am having is when user use Excel Export the whole criteria form get loss and I end up having a browser page with Excle Spreadsheet in it. I can' go to crietria page any more unless I close the Browser and start over.

Here is the code I use to Export Data to Excel from Datagrid

Public Shared Sub DataGridToExcel(ByVal dgExport As DataGrid, ByVal response As HttpResponse)
'clean up the response.object

response.Clear()
response.Charset = ""
'set the response mime type for excel
response.ContentType = "application/vnd.ms-excel"
'create a string writer
Dim stringWrite As New System.IO.StringWriter()
'create an htmltextwriter which uses the stringwriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)

'instantiate a datagrid
Dim dg As New DataGrid()
' just set the input datagrid = to the new dg grid
dg = dgExport

' Make the header text bold
dg.HeaderStyle.Font.Bold = True


'tell the datagrid to render itself to our htmltextwriter
dg.RenderControl(htmlWrite)
'output the html
response.Write(stringWrite.ToString)
response.End()
End Sub


Can you guys give me suggestion how to do it correctly.


Thanks
Tanweer
 
Back
Top