It looks like the 'MainContent_GridView1' is inside the run at server tag, What am I missing?
HTML markup
Error details
-------------------
System.Web.HttpException was unhandled by user code
ErrorCode=-2147467259
Message=Control 'MainContent_GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
Source=System.Web
WebEventCode=0
StackTrace:
at System.Web.UI.Page.VerifyRenderingInServerForm(Control control)
at System.Web.UI.WebControls.GridView.Render(HtmlTextWriter writer, Boolean renderPanel)
at System.Web.UI.WebControls.GridView.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at SOWTimeReporting.ExportToExcel.btnExportToExcel_Click(Object sender, EventArgs e) in C:\Users\z533560\Documents\Visual Studio 2010\Projects\SOWTimeReporting\ExportToExcel.aspx.vb:line 204
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
DougP
Code:
Dim queryTrans As String = CreateExportToExcelSQLString(TheVendor, TheMonth)
Me.GridView1.DataSource = PopulateGridwithSQL(queryTrans)
Me.GridView1.DataBind()
Response.Clear()
Response.Buffer = True
Response.AddHeader("Content-Disposition", "attachment; filename=MyExcelFileName.xls")
Dim writer As New System.IO.StringWriter()
Dim html As New System.Web.UI.HtmlTextWriter(writer)
Me.GridView1.RenderControl(html) ' <<<<< Error happens on this line
Response.Write(writer)
Response.End()
Code:
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="ExportToExcel.aspx.vb" Inherits="SOWTimeReporting.ExportToExcel" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
[b][COLOR=red]<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">[/color][/b]
Choose Vendor
<asp:DropDownList ID="ddlChooseVendor" runat="server" AutoPostBack="True">
</asp:DropDownList>
<br />
Choose Month
<asp:DropDownList ID="ddlChooseMonth" runat="server" AutoPostBack="True">
</asp:DropDownList>
<asp:Button ID="btnExportToExcel" runat="server" Text="Export To Excel"
Width="129px" />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</asp:Content>
-------------------
System.Web.HttpException was unhandled by user code
ErrorCode=-2147467259
Message=Control 'MainContent_GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
Source=System.Web
WebEventCode=0
StackTrace:
at System.Web.UI.Page.VerifyRenderingInServerForm(Control control)
at System.Web.UI.WebControls.GridView.Render(HtmlTextWriter writer, Boolean renderPanel)
at System.Web.UI.WebControls.GridView.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at SOWTimeReporting.ExportToExcel.btnExportToExcel_Click(Object sender, EventArgs e) in C:\Users\z533560\Documents\Visual Studio 2010\Projects\SOWTimeReporting\ExportToExcel.aspx.vb:line 204
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
DougP