hi,
there, i need to know why is it i get this error when i run the web site.A page can have only one server-side Form tag

Recommended Answers

All 3 Replies

This can happen if you are using master pages and you have a <form runat="server"> element in your master page and in your web content page you have another <form runat="server"> . Here is an example.

Master Page:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="daniweb.web.Site1" %>
<!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">
    <link rel="stylesheet" href="Stylesheet1.css" type="text/css" />
    <title>Master Page</title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <center> 
            <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
            </asp:ContentPlaceHolder>

Note in the above example the content place holder is inside the <form> element. Now on your child page:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Page1.aspx.cs" Inherits="daniweb.web.Page1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
	<form id="hello" runat="server">
		<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" OnClientClick="javascript:self.close(); " />
	</form>
</asp:Content>

Resulting in: [HttpException (0x80004005): A page can have only one server-side Form tag.] Here is an example of two embedded forms causing that error without using master pages:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="daniweb.web.Default" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
			<form id="form2" runat="server">
				<p>hello</p>
			</form>
    </div>
    </form>
</body>
</html>

A page can have only one server-side Form tag

As the error message itself suggests, a web page can have only one run at server form tag.

Please check your markup, you must have more than one form tags written there.

commented: worthless post +0

please mark this thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.