Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-10-19
5
Medium Priority
?
8,538 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

877 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