Solved

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

Posted on 2006-10-19
5
8,394 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
Comment Utility
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
Comment Utility
<%@ 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
Comment Utility
0
 
LVL 12

Expert Comment

by:craskin
Comment Utility
you're databinding gridview1 twice.
0
 
LVL 7

Author Comment

by:brdrok
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now