Javacadabra
Javacadabra

Reputation: 5758

One form tag on page in ASP.NET Issue

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.

Upvotes: 2

Views: 756

Answers (2)

Nicholas Aysen
Nicholas Aysen

Reputation: 580

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.

Upvotes: 0

connersz
connersz

Reputation: 1213

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.

Upvotes: 1

Related Questions