FOUND SOLUTION: See reply!
I am trying to learn ASP and have developed a page with a GridView with paging, theme and sorting turned off. Although it is within the form tag on the "default.aspx" page, I still get the following error from "default.aspx.
vb" page:
Control 'Campus' of type 'GridView' must be placed inside a form tag with runat=server.
Source Error:
Line 30: oHtmlTextWriter = New System.Web.UI.HtmlTextWriter (oStringWriter)
Line 31: Me.Campus.RenderControl(oHtmlTextWriter)
Line 32: Response.Write(oStringWriter.ToString())
My code contains snippets from the web (trying to save just the Grid control to excel) but I get the full page if I rem Line 31 and the above error if I don't.
If someone would be kind enough to explain why this doesn't work, I would be most grateful and I thank you in advance. MKS
-------- Code --------
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim oStringWriter As System.IO.StringWriter
Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
'Response.AddHeader("Content-Disposition", "attachment filename=""" & filename & """")
Response.ContentEncoding = System.Text.Encoding.ASCII
Response.Charset = ""
EnableViewState = False
oStringWriter = New System.IO.StringWriter()
oHtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
Me.Campus.RenderControl(oHtmlTextWriter)
Response.Write(oStringWriter.ToString())
End Sub
[Note: This attempt to get past the control issue gives me a Page error. I had placed it beneath the above sub. Why doesn't this work?]
' Override the Render method to ensure that this control
' is nested in an HtmlForm server control, between a <form runat=server>
' opening tag and a </form> closing tag.
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
' Ensure that the control is nested in a server form.
If Not (Page Is Nothing) Then
Page.VerifyRenderingInServerForm(Me)
End If
MyBase.Render(writer)
End Sub