ASP.NET 2.0 - Export to Excel - Control 'ctl06_grd1_pager_-4_ctl01' of type 'o' must be placed inside a form tag with runat=server.

Hi,
I've got the below function that exports a grid to excel. It works fine for all the user control pages i have, except for one. It gives an error says "Control 'ctl06_grd1_pager_-4_ctl01' of type 'o' must be placed inside a form tag with runat=server."

The Code:
        Response.ContentType = "application/vnd.ms-excel"
        Response.AppendHeader("Content-Disposition", "attachment; filename=" & Me.Page.Form.ID & ".xls")
        Response.Charset = ""
        Me.EnableViewState = False
        Dim tw As New System.IO.StringWriter
        Dim hw As New System.Web.UI.HtmlTextWriter(tw)
        grd1.AllowSorting = False 'remove hyperlinks
        LoadData()
        BindGrid()
        grd1.RenderControl(hw)
        Response.Write(tw.ToString())
        Response.End()
feesuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ethothsCommented:
What this error is saying is that the control must be inside a form tag,...

<form runat="server">
  Your control here.
</form>

If you've added the control declarativly make sure you have the for tags outside of your control.

If you added it programatically, make sure yu add it to the forms controls not to the page controls as the latter will simply append it to the bottom of the page OUTSIDE the form tags.
0
feesuAuthor Commented:
It is a user control. And usually it doesn't have a form tag in the HTML pane!
Below is full html:




<HTML>
      <HEAD>
            <LINK href="../../styles.css" rel="stylesheet">
                   </HEAD>
      <BODY dir="ltr" bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0" marginheight="0"
            marginwidth="0">
            <TABLE  id="tblMain" borderColor="#993333" cellSpacing="0" cellPadding="0"
                  border="0" width="100%">
                  <TR>
                        <TD  style="HEIGHT: 30px"><uc1:desktopmoduletitle id="DesktopModuleTitle1" runat="server"></uc1:desktopmoduletitle>
                  <TR>
                        <TD><asp:label id="lblMessage" runat="server" CssClass="Error" ></asp:label><input id="txtSortedBy"
                        runat="server" style="width: 24px; background-color: blue" type="hidden" /><input
                            id="txtSortedAs" runat="server" style="width: 24px; background-color: blue" type="hidden" /></TD>
                  </TR>
                  <TR>
                        <TD valign="middle">
                    <table id="Table11" border="0" cellpadding="0" cellspacing="0" width="100%">
                        <tr>
                            <td width="100">
                                <table id="Table1" border="0" bordercolor="red" cellpadding="0" cellspacing="0" style="width: 568px">
                                    <tr>
                                        <td style="height: 42px">
                                            <asp:DropDownList ID="cboFilterBy" runat="server" AutoPostBack="True" CssClass="text"
                                                Width="150px">
                                                <asp:ListItem>[Select]</asp:ListItem>
                                            </asp:DropDownList></td>
                                        <td valign="middle" style="height: 42px">
                                            <asp:TextBox ID="txtKeyword" runat="server" CssClass="text" Visible="False" Width="300px"></asp:TextBox>
                                            <asp:DropDownList ID="cboFilterValue" runat="server" CssClass="text" Width="300px">
                                            </asp:DropDownList></td>
                                        <td align="center" style="width: 28px; height: 42px;" valign="middle">
                                            <asp:Button ID="btnFilter" runat="server" CssClass="text" Text="Go" /></td>
                                        <td align="center" style="width: 87px; height: 42px;" valign="middle">
                                            <asp:Button ID="btnResetFilter" runat="server" CssClass="text" Text="Reset Filter" /></td>
                                        <td align="center" style="width: 87px; height: 42px" valign="middle">
                                            <asp:Button ID="btnExport" runat="server" CssClass="text" Text="Export" /></td>
                                    </tr>
                                </table>
                            </td>
                            <td align="right"><table id="Table2" border="0" bordercolor="red" cellpadding="0" cellspacing="0" style="height: 30px;">
                                <tr>
                                    <td width="100" align="right" valign="top">
                                        <asp:LinkButton ID="btnRefresh" runat="server" CssClass="link">Refresh Module</asp:LinkButton></td>
                                </tr>
                                <tr>
                                    <td align="right" valign="bottom" width="100">
                                        <asp:LinkButton ID="btnAddNew" runat="server" CssClass="link">Add New</asp:LinkButton></td>
                                </tr>
                            </table>
                            </td>
                        </tr>
                    </table>
                </TD>
                  </TR>
                  <TR>
                        <TD>
                    &nbsp;<C1WEBGRID:C1WEBGRID id="grd1" runat="server" Width="100%" DataKeyField="ikey"
                                     GroupByCaption="You can drag a column here to group by it :)" AllowColMoving="True"
                                    BorderWidth="1px" AutoGenerateColumns="False" DefaultRowHeight="20px"
                                    CellPadding="2" GroupIndent="" gridlines="Horizontal" cssclass="text" font-bold="False" font-italic="False" font-overline="False" font-strikeout="False" font-underline="False" allowpaging="True" allowsorting="True" pagesize="20" >
                    <footerstyle font-bold="False" font-italic="False" font-overline="False" font-strikeout="False"
                        font-underline="False" forecolor="#A0AEC9" wrap="True" />
                    <Columns>
<C1WebGrid:C1BoundColumn DataField="IKey" Visible="False" HeaderText="IKey"></C1WebGrid:C1BoundColumn>
<C1WebGrid:C1BoundColumn DataField="FullName" SortExpression="FullName" HeaderText="FullName">
<ItemStyle Wrap="True" HorizontalAlign="Left" Font-Italic="False" Font-Strikeout="False" Font-Underline="False" Font-Overline="False" Font-Bold="False"></ItemStyle>

<HeaderStyle Wrap="True" HorizontalAlign="Left" Font-Italic="False" Font-Strikeout="False" Font-Underline="False" Font-Overline="False" Font-Bold="False"></HeaderStyle>
</C1WebGrid:C1BoundColumn>
<C1WebGrid:C1BoundColumn DataField="JobTitle" Visible="False" SortExpression="JobTitle" HeaderText="JobTitle"></C1WebGrid:C1BoundColumn>
<C1WebGrid:C1BoundColumn DataField="Company" SortExpression="Company" HeaderText="Company"></C1WebGrid:C1BoundColumn>
<C1WebGrid:C1BoundColumn DataField="CompanyAddress" Visible="False" SortExpression="CompanyAddress" HeaderText="CompanyAddress"></C1WebGrid:C1BoundColumn>
<C1WebGrid:C1BoundColumn DataField="ResidenceAddress" Visible="False" SortExpression="ResidenceAddress" HeaderText="ResidenceAddress"></C1WebGrid:C1BoundColumn>
<C1WebGrid:C1BoundColumn DataField="BusinessTelephone" Visible="False" SortExpression="BusinessTelephone" HeaderText="BusinessTelephone"></C1WebGrid:C1BoundColumn>
<C1WebGrid:C1BoundColumn DataField="PersonalTelephone" Visible="False" SortExpression="PersonalTelephone" HeaderText="PersonalTelephone"></C1WebGrid:C1BoundColumn>
<C1WebGrid:C1BoundColumn DataField="Mobile" SortExpression="Mobile" HeaderText="Mobile"></C1WebGrid:C1BoundColumn>
<C1WebGrid:C1BoundColumn DataField="Fax" Visible="False" SortExpression="Fax" HeaderText="Fax"></C1WebGrid:C1BoundColumn>
<C1WebGrid:C1BoundColumn DataField="Email" SortExpression="Email" HeaderText="Email">
<ItemStyle Wrap="True" HorizontalAlign="Left" Font-Italic="False" Font-Strikeout="False" Font-Underline="False" Font-Overline="False" Font-Bold="False"></ItemStyle>

<HeaderStyle Wrap="True" HorizontalAlign="Left" Font-Italic="False" Font-Strikeout="False" Font-Underline="False" Font-Overline="False" Font-Bold="False"></HeaderStyle>
</C1WebGrid:C1BoundColumn>
<C1WebGrid:C1BoundColumn DataField="UserPassword" Visible="False" SortExpression="UserPassword" HeaderText="UserPassword"></C1WebGrid:C1BoundColumn>
<C1WebGrid:C1BoundColumn DataField="IsActive" Visible="False" SortExpression="IsActive" HeaderText="IsActive"></C1WebGrid:C1BoundColumn>
<C1WebGrid:C1BoundColumn DataField="IsUser" Visible="False" SortExpression="IsUser" HeaderText="IsUser"></C1WebGrid:C1BoundColumn>
<C1WebGrid:C1BoundColumn DataField="ExpiryDate" Visible="False" SortExpression="ExpiryDate" HeaderText="ExpiryDate"></C1WebGrid:C1BoundColumn>
<C1WebGrid:C1BoundColumn DataField="IsTrial" Visible="False" SortExpression="IsTrial" HeaderText="IsTrial"></C1WebGrid:C1BoundColumn>
<C1WebGrid:C1BoundColumn DataField="LastLogin" SortExpression="LastLogin" HeaderText="Last Login"></C1WebGrid:C1BoundColumn>
<C1WebGrid:C1TemplateColumn>
<ItemStyle Width="200px" Wrap="True" Font-Italic="False" Font-Strikeout="False" Font-Underline="False" Font-Overline="False" Font-Bold="False"></ItemStyle>

<HeaderStyle Wrap="True" Font-Italic="False" Font-Strikeout="False" Font-Underline="False" Font-Overline="False" Font-Bold="False"></HeaderStyle>
<ItemTemplate>
<TABLE id="tblTools" cellSpacing=0 cellPadding=0 width="100%" border=0><TBODY><TR><TD align=center><asp:LinkButton id="btnRoles" runat="server" CssClass="link" __designer:wfdid="w13">Roles</asp:LinkButton></TD><TD align=center><asp:LinkButton id="btnSubscriptions" runat="server" CssClass="link" __designer:wfdid="w14" Enabled="False">Subscriptions</asp:LinkButton></TD><TD align=center><asp:LinkButton id="lnkEdit" runat="server" CssClass="link" __designer:wfdid="w15">Edit</asp:LinkButton></TD></TR></TBODY></TABLE>
</ItemTemplate>

<FooterStyle Wrap="True" Font-Italic="False" Font-Strikeout="False" Font-Underline="False" Font-Overline="False" Font-Bold="False"></FooterStyle>
</C1WebGrid:C1TemplateColumn>
</Columns>

<PagerStyle Mode="NumericPages" ForeColor="#A0AEC9" Wrap="True" Font-Italic="False" Font-Strikeout="False" Font-Underline="False" Font-Overline="False" Font-Bold="False"></PagerStyle>
                    <headerstyle font-bold="False" font-italic="False" font-overline="False" font-strikeout="False"
                        font-underline="False" forecolor="#A0AEC9" wrap="True" />
</C1WEBGRID:C1WEBGRID></TD>
                  </TR>
            </TABLE>
      </BODY>
</HTML>
0
ethothsCommented:
It does not have a form tag in the html pane because the user copntrol is designed to go into the form on the page. The for is on the page not the user control. The code you have given here include the <html> and <body> tages. These too are usually supplied by the page not the user control.

I'm not sure if the code you've supplied is the source or the output. As source it has no control or page directives, As output the asp tags have not been rendered correctly.

You should ghave 2 files...
1)  A page with a Page directive and a user control directive at the top. This page will have a form tag just inside the body. In this file you should have a tag representing your user control.

2) A user control with a control directive and no <HTML>, <BODY> or <FORM> tags.

Here's an example...

Page...
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Register Src="WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %>
<!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>
                <uc1:WebUserControl ID="WebUserControl1" runat="server" />
            </div>
        </form>
    </body>
</html>

User Control...
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<div>
    This is My User Control
</div>


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.