By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,312 Members | 1,248 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,312 IT Pros & Developers. It's quick & easy.

Export to Excel: form tag with runat=server error

P: n/a
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

Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

Nov 19 '05 #2

P: n/a
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

"zdrakec" wrote:
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

Nov 19 '05 #3

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

Sorry I couldn't help...

zdrakec

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.