Solved

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

Posted on 2006-10-19
5
8,426 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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