简体   繁体   中英

Gridview inside of form running at server throws “'GridView' must be placed inside aform tag with runat=server”

I've seen a looot of questions about this and I've tried to overload/override VerifyRenderingInServerForm method and it isn't helping (the compiler complains if I try overrides ).

To be sure:

In the master page, we have:

<form id="form1" runat="server">

so it definitely is inside a form/server tag.

The gridview has:

<asp:GridView
    ItemStyle-CssClass="Item"
    ID="grdInfo"
    runat="server"
    CssClass="grdCss"
    Width="100%"
    CellPadding="3"
    AutoGenerateColumns="false"
    HeaderStyle-CssClass="Header"
    RowStyle-CssClass="Item"
    AlternatingRowStyle-CssClass="AltItem"
    AllowSorting="false"
    AllowPaging="false">
    ....

Unlike other people, I'm not trying to render excel. I am, however, attempting to bind to a enumerable collection :

Public Class colInfoSet
    Inherits CollectionBase

We use this type of object elsewhere without problems.

I just found out what the problem is. When the master page and child page/controls are loaded, the grid isn't rendered because it has no rows. The grid is then retrieved via ajax and then populated.

Since it was not rendered when the page was rendered, it cannot be added to the control tree.

Hence it doesn't work.

The solution I will be going with is to use a repeater instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM