Link to home
Start Free TrialLog in
Avatar of brdrok
brdrok

asked on

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

Hi,

I am getting the following error:

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

below is the code:

protected void Page_Load(object sender, EventArgs e)
    {
        System.IO.StringWriter tw = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);

        DataBridge.PrismPanc pp = new PrismPanc();
        System.Data.DataTable dtExport = pp.GetTodaysData();
        GridView1.DataSource = dtExport;
        GridView1.DataBind();

        Excel.Application oXl;
        Excel._Workbook oWb;
        Excel._Worksheet oSheet;

        hw.WriteLine("<b><u><font size='5'>" +
            "Report for the Fiscal year: </font></u></b>");
        hw.WriteLine("<br>&mp;nbsp;");

        GridView1.HeaderStyle.Font.Bold = true;
        GridView1.DataBind();
        GridView1.RenderControl(hw);   //<-----generating the above error message

        // Write the HTML back to the browser.
        Response.ContentType = "application/vnd.ms-excel";
        this.EnableViewState = false;
        Response.Write(tw.ToString());
        Response.End();
Avatar of gangwisch
gangwisch

you need to post your designer code but must likely you need to have it in this format
<form runat="server">
<asp:gridview>...
</form>
Avatar of brdrok

ASKER

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;</div>
        <asp:GridView ID="GridView1" runat="server" Height="263px" Width="633px">
        </asp:GridView>
    </form>
</body>
</html>

The GridView is within the <form...> and </form> tags.
ASKER CERTIFIED SOLUTION
Avatar of brwwiggins
brwwiggins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you're databinding gridview1 twice.
Avatar of brdrok

ASKER

I am not exactly sure what this whole enableEventValidation bit is all about but turning it to false seems to do the trick.  

enableEventValidation ="false"