Last post Feb 17, 2006 06:24 AM by stevedotnut
Feb 15, 2006 08:37 PM|samir25|LINK
i need to have a button on clicking to which the user can download a query result data in the excel sheet. i tried the code that i pasted below
Dim oStringWriter As New System.IO.StringWriter
Dim oHTMLTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)
after using the above code i get this error
Control 'dnn_ctr623_LoginCheck_dgDisplayModules__ctl2__ctl0' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server
i m using ascx file...i cannot use form tags their..any help ..feedback inputs on this?
thanks a lot
Feb 16, 2006 05:23 AM|stevedotnut|LINK
Downloads like this are best handled by an .aspx page like download.aspx. I generally have a button or a link button in my .ascx control which redirects the browser to download.aspx passing any parameters needed by download.aspx. I then put code to handle
the download in download.aspx overriding the Render Event.
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim enc As Encoding = Encoding.GetEncoding(Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ANSICodePage)
dgExcel.DataSource = GetYourData()
Response.ContentType = "application/ms-excel"
Response.ContentEncoding = Encoding.UTF7
Response.Charset = enc.BodyName
Catch ex As Exception
Response.Write("" & ex.Message & " Please Use your Browser Back button to Return
Feb 16, 2006 08:40 PM|samir25|LINK
thanks a lot steve for ur response.
i hope u r available for the response further. can i do to a aspx page from ascx page... this is slightly confusing as all the modules have ascx pages...can u explain...
i just didnt understand what u did above... can pls help explian.
really appreciate it..
Feb 17, 2006 06:24 AM|stevedotnut|LINK
Response.Redirect(Me.ModulePath & "download.aspx?mid=" & ModuleId & "&portid=" & PortalId & "&tabid=" & TabId)
The user's browser will not navigate to download.aspx, but instead will display the download dialog box..
As for the code in the first post, you can copy and paste it into a new .aspx page. Change the name of the Datagrid to what you like, and set the DataGrid.DataSource property to your data. You can retrieve moduleID from the
query string to use to access your data.
If the data is only intended for authenticated users, I usually check if the user is allowed to access the data.
If you like, send me a private message, I will send you a complete download page as an example.