2

I am getting this error when trying to run my project on localhost

Exception Details: System.Web.HttpException: A page can have only one server-side Form tag

This is my ASP.NET form

 <form id="consultationform" runat="server">

    <%-- Consultation  --%>
    <%-- Name --%>
    <asp:Label ID="namelabel" runat="server" Text="Name"></asp:Label>
    <asp:TextBox ID="namebox" runat="server"></asp:TextBox><br />

    <%-- email --%>
    <asp:Label ID="emaillabel" runat="server" Text="Email"></asp:Label>
    <asp:TextBox ID="emailbox" runat="server"></asp:TextBox><br />

    <%-- restaurant --%>
    <asp:Label ID="restaurantlabel" runat="server" Text="Restaurant"></asp:Label>
    <asp:TextBox ID="restaurantbox" runat="server"></asp:TextBox><br />

    <%-- Address --%>
    <asp:Label ID="addresslabel" runat="server" Text="Address"></asp:Label>
    <asp:TextBox ID="addressbox1" runat="server"></asp:TextBox><br />
    <asp:TextBox ID="addressbox2" runat="server"></asp:TextBox><br />
    <asp:TextBox ID="addressbox3" runat="server"></asp:TextBox><br />

    <%-- County --%>
    <asp:Label ID="countylabel" runat="server" Text="County"></asp:Label>
    <asp:DropDownList ID="countrydropdown" runat="server" 
    DataSourceID="CountySqlDataSource" DataTextField="CountyName" 
    DataValueField="CountyName" AppendDataBoundItems="True" AutoPostBack="True">
    <asp:ListItem Value="" Text="Select a County"></asp:ListItem>
    </asp:DropDownList>
<asp:SqlDataSource ID="CountySqlDataSource" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
    SelectCommand="SELECT [CountyName] FROM [Counties]"></asp:SqlDataSource>
<br />

    <%-- Telephone --%>
    <asp:Label ID="telephonelabel" runat="server" Text="Telephone"></asp:Label>
    <asp:TextBox ID="telephonebox" runat="server"></asp:TextBox><br />

    <%-- Calendar --%>
    <asp:Label ID="datelabel" runat="server" Text="Date (What suits you?)"></asp:Label><asp:Calendar
        ID="Calendar1" runat="server"></asp:Calendar><br />

    <%-- Additional Info --%>
    <asp:Label ID="infolabel" runat="server" Text="Additional Information (That may help us further)"></asp:Label><br />
    <asp:TextBox ID="infobox" runat="server"></asp:TextBox><br />

    <%-- Menu Upload --%>
    <asp:Label ID="menulabel" runat="server" Text="Menu"></asp:Label><asp:FileUpload
        ID="FileUpload1" runat="server" /><br />

    <%-- Book Button --%>
    <asp:Button ID="bookbtn" runat="server" Text="Book Now" />

    </form>

I don't understand why it is happening. I only have one form tag on the page. Any help on the matter is much appreciated.

Should note, page renders completely fine if I remove the form tag.

Javacadabra
  • 5,578
  • 15
  • 84
  • 152
  • 4
    If you're using a masterpage then the form tag is probably already in it... – Laurent S. Nov 20 '13 at 14:34
  • 2
    Is this inside a master page by chance? – tymeJV Nov 20 '13 at 14:34
  • Just noticed that there, yes it is. So does that mean I do not have to include my form tag at all? – Javacadabra Nov 20 '13 at 14:38
  • 1
    @Javacadabra: That's exactly what it means. A master page is used to hold things common to all of your web pages. – NotMe Nov 20 '13 at 14:43
  • @ChrisLively In the case of my form, if it only occurs on one of my pages do I still include that in the Master page? Sorry if that's a stupid question, we only began studying ASP today! – Javacadabra Nov 20 '13 at 14:49
  • @Javacadabra: a form tag is required for certain aspects of .net to work, such as viewstate etc. – NotMe Nov 20 '13 at 15:37

2 Answers2

1

If you are using a masterpage, remove the form from your webform and inside the masterpage form add a content placeholder.

Use that content placeholder within your webforms like you were trying to use the form.

You may need to click the little arrow to the right of the content placeholder in the form in order to enable it.

connersz
  • 1,153
  • 3
  • 23
  • 64
  • I understand what you are saying, but having a bit of trouble implementing it. Would you be able to provide a sample of code please? – Javacadabra Nov 20 '13 at 14:47
0

in your master page, you should have at least:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs"Inherits="WebApplication1.Site1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

you can then remove all other form tags from your project, beacuse the master has one in use. remember to add content pages properly also, in the body, contentplaceholder.

Nicholas Aysen
  • 568
  • 3
  • 18
  • 40