MultiView cannot have children of type 'GridView'. It can only have children of type View

asp.net, c#, multiview

Solution

I was getting the exact error, but in my case I had forgotten to set `runat="server"` in the View control.

If one doesn't include `runat="server"` then that control simply doesn't exist for the backend. I hope this helps.

Problem

I have the following asp.net code ``` asp:MultiView runat="server" ID="mvPaymentsOnProperty" ActiveViewIndex="0"> <asp:View runat="server" ID="vPaymentsMadeOnProperty"> <br /> <asp:GridView runat="server" ID="gvPaymentsMadeOnProperty" AutoGenerateColumns="false" EmptyDataText="bla bla"> <Columns> <asp:BoundField HeaderText="bla" DataField="bla" /> <asp:BoundField HeaderText="foo" DataField="bar" /> </Columns> </asp:GridView> </asp:View> <asp:View runat="server" ID="vNoPaymentsMadeOnProperty"> Some sort of error </asp:View> </asp:MultiView> ``` When I try to load the page, I get the following error MultiView cannot have children of type 'GridView'. It can only have children of type View. I've collapsed the Multiview code and the only two children it has are the views. Is it complaining because of the contents of the view? Because otherwise that'd make it almost completely useless. How do I fix this?

Original source