1
votes

So I'm the new guy on the dev team, trying to update a "Dashboard" type page, which is the default landing page for our users. The default.aspx page consists of 16 Web User Controls (.ascx). I've been asked to add stock "widget" on the dashboard, so users can monitor our company's stock symbol. To allow for different timeframes (1 day, 5 day, 3 month, etc) I was planning on using a Menu (tabs) within a new .ascx. When I try to use a menu, I get the error "Control 'StockDisplay_StockMenu' of type 'Menu' must be placed inside a form tag with runat=server". If I wrap the menu in form tags, I get the "A page can have only one server-side Form tag" error.

Most search results suggest looking at the Master Page, but we're not using one here. I checked The default.aspx page, and it does not have any form tags. Other searches suggested removing < head> and < body> tags in the .ascx, which I've done, but still I have the issue.

Here's my stripped down code, which still produces the error:

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="UC_StockDisplay.ascx.vb" Inherits="UC_StockDisplay" %>
<%@ Import Namespace="System.Data" %>

<form id="Form1" runat="server">
    <asp:Menu ID="StockMenu" runat="server">
        <Items>
            <asp:MenuItem Text="One Day" />
            <asp:MenuItem Text="Five Days" />
            <asp:MenuItem Text="Three Months" />
            <asp:MenuItem Text="Six Months" />
            <asp:MenuItem Text="One Year" />
        </Items>
     </asp:Menu>
</form>

Here's the default.aspx:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<%@ Register src="UC_HelpUs.ascx" tagname="HelpUs" tagprefix="uc1" %>
<%@ Register src="UC_ImportantNumbers.ascx" tagname="ImportantNumbers" tagprefix="uc2" %>
<%@ Register src="UC_ImportantLinks.ascx" tagname="ImportantLinks" tagprefix="uc3" %>
<%@ Register src="UC_Printers.ascx" tagname="Printers" tagprefix="uc4" %>
<%@ Register src="UC_WorkOrder.ascx" tagname="WorkOrder" tagprefix="uc5" %>
<%@ Register src="UC_RequestForms.ascx" tagname="UCRequestForms" tagprefix="uc6" %>
<%@ Register src="UC_MiscLinks.ascx" tagname="MiscLinks" tagprefix="uc7" %>
<%@ Register src="UC_Emergency.ascx" tagname="Emergency" tagprefix="uc8" %>
<%@ Register src="UC_Floorplan.ascx" tagname="Floorplan" tagprefix="uc9" %>
<%@ Register src="UC_Directory.ascx" tagname="Directory" tagprefix="uc10" %>
<%@ Register src="UC_Weather.ascx" tagname="Weather" tagprefix="uc11" %>
<%@ Register src="UC_Holiday.ascx" tagname="Holiday" tagprefix="uc12" %>
<%@ Register src="UC_CoreValues.ascx" tagname="CoreValues" tagprefix="uc14" %>
<%@ Register src="UC_MyInfo.ascx" tagname="MyInfo" tagprefix="uc15" %>
<%@ Register src="UC_Travel.ascx" tagname="Travel" tagprefix="uc16" %>
<%@ Register src="UC_StockDisplay.ascx" tagname="StockDisplay" tagprefix="uc17" %>


<!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>IT Helpdesk</title>
</head>
<body style="background-color:#1B5B9D;">

    <center>
    <a href="/"><img src="images\banner2.gif" border=0></a><br>
    <font face="Courier New Bold" size=5 color=white>Helpdesk 3.5</font><br>
    <table width=100% cellspacing=10>
        <tr>
            <td width="33%" valign=top>
                <uc1:HelpUs ID="HelpUs" runat="server" />
                <br>
                <uc3:ImportantLinks ID="ImportantLinks" runat="server" />
                <br>                
                <uc10:Directory ID="Directory" runat="server" />
                <br>            
                <uc6:UCRequestForms ID="UCRequestForms" runat="server"/>
                <br>
                <uc7:MiscLinks ID="MiscLinks" runat="server" />
            </td>
            <td width="33%" valign=top align=center>
                <uc5:WorkOrder ID="WorkOrder" runat="server" />
                <br>
                <uc8:Emergency ID="Emergency" runat="server" />
                <br>
                <uc2:ImportantNumbers ID="ImportantNumbers" runat="server" />
                <br>
                <uc11:Weather ID="Weather" runat="server" />

    <td width="33%" valign=top>
                <uc17:StockDisplay ID="StockDisplay" runat="server" />
                <br />
                <uc9:Floorplan ID="Floorplan" runat="server" />
                <br>
                <uc4:Printers ID="Printers" runat="server" />
                <br>
                <uc15:MyInfo ID="MyInfo" runat="server" />
                <br>
                <uc14:CoreValues ID="CoreValues" runat="server" />
                <br>
                <uc12:Holiday ID="Holiday" runat="server" />
                <br />
                <uc16:Travel ID="Travel" runat="server"></uc16:Travel>
            </td>
        </tr>
    </table>
    </center>


</body>
</html>
1
A control can't have a form tag. So you need to strip that out. Can you show an actual stripped down page showing how you are placing the control in it?NotMe
Chris - it's exactly the same code (minus the form tags). As explained in the question, if I exclude the form tags, I get an error suggesting I need them.Karl
I was asking about the page the control goes in. How is that structured, where are you putting the control, is it inside of the pages form element?NotMe
Chris - this web user control is on the default.aspx page. There are no form tags on that page. I'll see if I can post it in a little bit.Karl

1 Answers

4
votes

After adding one control you have a form with runat="server" tag:

<form id="Form1" runat="server">
    <asp:Menu ID="StockMenu" runat="server">

You already mentioned you have 16 usercontrol in one page. So you have 16 forms with runat="server" tag. Which is not allowed.

Solution: As Chris Lively suggested, strip out the the form tag from your wsercontrols. Add just one form tag in the page. You should be ok.

Here's how should all your controls should look like:

<asp:Menu ID="Menu1" runat="server">
    <Items>
        <asp:MenuItem Text="One Day" />
        <asp:MenuItem Text="Five Days" />
        <asp:MenuItem Text="Three Months" />
        <asp:MenuItem Text="Six Months" />
        <asp:MenuItem Text="One Year" />
    </Items>
</asp:Menu>

And your page should look like:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<%@ Register src="UC_HelpUs.ascx" tagname="HelpUs" tagprefix="uc1" %>
<%@ Register src="UC_ImportantNumbers.ascx" tagname="ImportantNumbers" tagprefix="uc2" %>
<%@ Register src="UC_ImportantLinks.ascx" tagname="ImportantLinks" tagprefix="uc3" %>
<%@ Register src="UC_Printers.ascx" tagname="Printers" tagprefix="uc4" %>
<%@ Register src="UC_WorkOrder.ascx" tagname="WorkOrder" tagprefix="uc5" %>
<%@ Register src="UC_RequestForms.ascx" tagname="UCRequestForms" tagprefix="uc6" %>
<%@ Register src="UC_MiscLinks.ascx" tagname="MiscLinks" tagprefix="uc7" %>
<%@ Register src="UC_Emergency.ascx" tagname="Emergency" tagprefix="uc8" %>
<%@ Register src="UC_Floorplan.ascx" tagname="Floorplan" tagprefix="uc9" %>
<%@ Register src="UC_Directory.ascx" tagname="Directory" tagprefix="uc10" %>
<%@ Register src="UC_Weather.ascx" tagname="Weather" tagprefix="uc11" %>
<%@ Register src="UC_Holiday.ascx" tagname="Holiday" tagprefix="uc12" %>
<%@ Register src="UC_CoreValues.ascx" tagname="CoreValues" tagprefix="uc14" %>
<%@ Register src="UC_MyInfo.ascx" tagname="MyInfo" tagprefix="uc15" %>
<%@ Register src="UC_Travel.ascx" tagname="Travel" tagprefix="uc16" %>
<%@ Register src="UC_StockDisplay.ascx" tagname="StockDisplay" tagprefix="uc17" %>


<!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 id="Head1" runat="server">
    <title>IT Helpdesk</title>
</head>
<body style="background-color:#1B5B9D;">
<form id="form1" runat="server">
    <%-- your usercontrols and other tags --%>
</form>

EDIT: As you mentioned other usercontrols don't have forms, just adding form tag in the main page and remove that tag from usercontrol should solve your problem.