Solved

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.

Posted on 2007-03-25
5
1,215 Views
Last Modified: 2008-01-09
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()
0
Comment
Question by:feesu
  • 2
5 Comments
 
LVL 11

Expert Comment

by:ethoths
ID: 18791445
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
 

Author Comment

by:feesu
ID: 18791473
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
 
LVL 11

Accepted Solution

by:
ethoths earned 125 total points
ID: 18791929
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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 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