G
Guest
I have a usercontrol that is loaded by a webform. The usercontrol populates
a datagrid which users need the capability to export data from the grid to
Excel. The problem is that when I attempt to export the data to excel I get
the following error message:
Control 'RoomReservationReport1_dgReservations__ctl2__ctl0' of type
'DataGridLinkButton' must be placed inside a form tag with runat=server.
My form tag is located in my web form not the usercontrol. My question is
how do I modify the following code to recognize the form runat=server tag in
the page instead of looking in the user control? Thank you!!
Private Sub btnExcel_Click(ByVal sender As System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles btnExcel.Click
Try
Response.Clear()
Response.Buffer = True
' Set the content type to Excel.
Response.ContentType = "application/vnd.ms-excel"
' Remove the charset from the Content-Type header.
Response.Charset = ""
' Turn off the view state.
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
' Get the HTML for the control.
dgReservations.RenderControl(hw)
' Write the HTML back to the browser.
Response.Write(tw.ToString())
' End the response.
Response.End()
Catch ex As Exception
Throw ex
Finally
End Try
a datagrid which users need the capability to export data from the grid to
Excel. The problem is that when I attempt to export the data to excel I get
the following error message:
Control 'RoomReservationReport1_dgReservations__ctl2__ctl0' of type
'DataGridLinkButton' must be placed inside a form tag with runat=server.
My form tag is located in my web form not the usercontrol. My question is
how do I modify the following code to recognize the form runat=server tag in
the page instead of looking in the user control? Thank you!!
Private Sub btnExcel_Click(ByVal sender As System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles btnExcel.Click
Try
Response.Clear()
Response.Buffer = True
' Set the content type to Excel.
Response.ContentType = "application/vnd.ms-excel"
' Remove the charset from the Content-Type header.
Response.Charset = ""
' Turn off the view state.
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
' Get the HTML for the control.
dgReservations.RenderControl(hw)
' Write the HTML back to the browser.
Response.Write(tw.ToString())
' End the response.
Response.End()
Catch ex As Exception
Throw ex
Finally
End Try