RobertNZana
asked on
Control must be placed inside a form tag
Getting this error...
Control 'mygridview' of type 'GridView' must be placed inside a form tag with runat=server.
I dynamically take a gridview, stored in a session var, and put it in the form's controls collection. Why am I getting this error?
Control 'mygridview' of type 'GridView' must be placed inside a form tag with runat=server.
I dynamically take a gridview, stored in a session var, and put it in the form's controls collection. Why am I getting this error?
Dim stw As New System.IO.StringWriter()
Dim htextw As New HtmlTextWriter(stw)
Dim mygridview As New GridView
mygridview = CType(Session("GridViewToExport"), GridView)
form1.Controls.Add(mygridview)
'render gridview control to excel
mygridview.RenderControl(htextw) ' ERROR OCCURS HERE
ASKER
Same exact error, even when using the placeholder solution.
It happens on the rendercontrol line.
It happens on the rendercontrol line.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. Seems to work well.
But when Excel opens the file it says "The file you are trying to open, xxxx.xls, is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you wat to open the file now?"
Do you know what this means?
But when Excel opens the file it says "The file you are trying to open, xxxx.xls, is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you wat to open the file now?"
Do you know what this means?
Add a PlaceHolder Control on the page where you want the GV to appear.
Then add gv to this ph.
e.g.
<asp:PlaceHolder ID="PlaceHolder1" runat="server" />
PlaceHolder1.Controls.Add(
e.g.:http://blog.krisvandermast.com/AddingADynamicControlToAPlaceholderControlAndWireUpTheEvent.aspx