Exporting to excel from a gridview in VB

I have the code below but when I run it I get the following error

Control 'GridView2' of type 'GridView' must be placed inside a form tag with runat=server.

The control does have that....any ideas?
Protected Sub btnExportToExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExportToExcel.Click
        Dim stringWrite As IO.StringWriter
        Dim htmlWrite As HtmlTextWriter
        Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")
        Response.Charset = ""
        Response.ContentType = "application/vnd.ms-xls"
        stringWrite = New IO.StringWriter
        htmlWrite = New HtmlTextWriter(stringWrite)
        GridView2.RenderControl(htmlWrite)  'error here
    End Sub

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bdb12Author Commented:
The aspx the runats are clearly there.....!

    <form id="form1" runat="server">
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2"
            Style="z-index: 111; left: 216px; position: absolute; top: 424px">
                <asp:BoundField DataField="CentreID" HeaderText="CentreID" InsertVisible="False"
                    ReadOnly="True" SortExpression="CentreID" />
Pratima PharandeCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bdb12Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.