Solved

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

Posted on 2006-10-19
5
8,442 Views
Last Modified: 2013-12-03
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();
0
Comment
Question by:brdrok
5 Comments
 
LVL 10

Expert Comment

by:gangwisch
ID: 17769538
you need to post your designer code but must likely you need to have it in this format
<form runat="server">
<asp:gridview>...
</form>
0
 
LVL 7

Author Comment

by:brdrok
ID: 17769577
<%@ 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.
0
 
LVL 20

Accepted Solution

by:
brwwiggins earned 500 total points
ID: 17770008
0
 
LVL 12

Expert Comment

by:craskin
ID: 17770476
you're databinding gridview1 twice.
0
 
LVL 7

Author Comment

by:brdrok
ID: 17772967
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"
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question