Hidden field giving error

Apr 18, 2011 at 8:12 PM
Edited Apr 18, 2011 at 9:15 PM

I've added the exporttoexcel button, Bound it to the gridview. It gives me the error 'Control 'c1id_hdnfld' of type 'HiddenField' must be placed inside a form tag with runat=server'.

Is there a problem with having hidden fields in the grid view used to populate the excel file? I've added eventvalidation = false to the page, as suggested in one of the threads. But that didn't help. Also added the preexport routine. The gridview is being populated on the fly.

Here is my code..
 <RK:ExportToExcel ID="ExportToExcel2" runat="server" ApplyStyleInExcel="True" Charset="utf-8"
                                       ContentEncoding="windows-1250" EnableHyperLinks="True"
                                       IncludeTimeStamp="True" PageSize="All" Text="Export To Excel"  />
                <!--Author: Rajesh K, Copyright 2007 All rights reserved. Use this control at your own risk. Author is not responsible for any defects or damages to your code.-->             
        <asp:GridView ID="sr_Grid" runat="server" AllowPaging="True" DataKeyNames="p_id,ch_id"
            EmptyDataText="No results." CellPadding="4"
                AutoGenerateColumns="False"  >
                <asp:TemplateField HeaderText="Link">

                      <asp:TemplateField >
                       <ItemTemplate >
                           <asp:HiddenField ID="c1id_hdnfld" runat="server" Value='<%# Bind("ch_id") %>'  />

Code behind..

 Protected Sub ExportToExcel2_PreExport(ByVal Sender As Object, ByVal e As System.EventArgs) Handles ExportToExcel2.PreExport
        ExportToExcel2.GridViewID = "sr_Grid"
        ExportToExcel2.ExportFileName = "sr.xls"
    End Sub

Could you please tell me what I am doing wrong? Thnx in advance.