Export to Excel: form tag with runat=server error

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
 
Z

zdrakec

Hello Russ:

Look at the html portion of your page. Add the text:

runat="server"

where your control is declared:

<form method="post" runat="server" etc.>
<ccl:webcontrol runat="server" etc.></ccl:webcontrol>
etc.
</form>

That corrected an identical problem for me.

Cheers,
zdrakec
 
G

Guest

zdrakec--

Thanks for your response. I double checked all the server controls and they
include the runat server tag. I also verified the html in the web form that
is loading the usercontrol. The code is below. Please let me know if you
think I've missed the point.

<form id="Form1" method="post" runat="server">
<uc1:RoomReservationReport id="RoomReservationReport1"
runat="server">
</uc1:RoomReservationReport>
</form>


Russ
 
Z

zdrakec

Looks like we need a higher authority: that's exactly what I was
suggesting.

Sorry I couldn't help...

zdrakec
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top