Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A page can have only one server-side Form tag 1

Status
Not open for further replies.

EthanSmith

Programmer
Mar 28, 2005
4
NL
Problem:
I use a masterfile. The page account.aspx loads in contentplaceholder3. I have created a form in my account.aspx, but when I try to add a 'ASP:textbox' field to my contact.aspx , I get a: "'TEXTBOX' must be placed inside a form tag with runat=server" error. When I do this, I get a: "A page can have only one server-side Form tag" error. So I don't know what to do now!
thx
 
I think you just need to add runat="server" to the <asp:textbox id=TEXTBOX> tag. Take out the form tag you added.
 
I already did that

CONTENT OF MY Master1.master:

<%@ Page Title="My homepage > Home" MasterPageFile="~/Master1.master" Language="VB" AutoEventWireup="false" CompileWith="Default.aspx.vb" ClassName="Default_aspx" %>

<asp:Content ID="Content3" ContentPlaceHolderID="CPHContent" Runat="server">
<form>
<table><tr><td style="width: 148px">
<asp:TextBox ID="TextBox1" Runat="server"> </asp:TextBox>
</td></tr>
</table>
</form>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CPHPageHeader" Runat="server">Home</asp:Content>

As you can see there is only one form-tag.
The moment i remove runat=server from the form tag, i get the error:"System.Web.HttpException: Control 'ctl00_CPHContent_TextBox1' of type 'TextBox' must be placed inside a form tag with runat=server"

When i add runat=server to the form tag i get:
"A page can have only one server-side Form tag"


MY MASTERPAGE LOOKS LIKE THIS:
<%@ Master Language="VB" CompileWith="Master1.master.vb" AutoEventWireup="false" ClassName="Master1_master" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "
<html xmlns=" >
<head runat="server">
<title>My homepage </title>
<LINK REL=stylesheet HREF="FSAStyle.css" TYPE="text/css">

</head>
<body bgcolor="#CBDFF3" class="bodytest">
<!--<form id="form1" runat="server">-->
<div>
<table width="1024" height="768" cellpadding="0" cellspacing="0" border="0">
<tr>
<td rowspan="2" width="114" bgcolor="white">
<asp:Image ID="Image1" Runat="server" ImageUrl="./Images/corfumap.gif" Height="100px"
Width="100px" />
</td>
<td></td>
</tr>
<tr>
<td valign="top" style="height: 77px">
<img src="../Images/Banner.gif" />
</td>
</tr>
<tr>
<td>
<asp:ContentPlaceHolder ID="CPHMenu" Runat="server">
<div id="staticMenu"></div>
</asp:ContentPlaceHolder>


</td>
<!-- </form>-->
<td>

<!-- TABLE IN WHICH CONTENT IS PLACED -->
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td width="15"></td>
<td>

<table width="800">
<tr>
<td class="PageHeader">
<asp:ContentPlaceHolder ID="CPHPageHeader" Runat="server"></asp:ContentPlaceHolder>
</td>
</tr>
<tr>
<td bgcolor="Black" height="1"></td>
</tr>
</table>
<br/><br/>


<asp:ContentPlaceHolder ID="CPHContent" Runat="server">
</asp:ContentPlaceHolder>
</td>
<td width="30"></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
</table>

</td>
</tr>
<tr>
<td></td>
<td>Privacy Statement | Contact</td>
</tr>
</table>
</div>
</body>
</html>
 
Just remove the <form> tag completely from your master control. e.g.
Code:
<asp:Content ID="Content3" ContentPlaceHolderID="CPHContent" Runat="server">  
<table><tr><td style="width: 148px">     
<asp:TextBox ID="TextBox1" Runat="server"> </asp:TextBox>     
</td></tr>
</table>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CPHPageHeader" Runat="server">Home</asp:Content>
Then, when it is rendered to the page, it can use the <form runat="server"> t ag from the aspx page.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
I believe you must be using ASP.net 2.0, in which I have 0 experience with Master Files. However, did you try putting form tags in the MASTER and take them out of Master1.master? I am not sure why you commmented the form tags out in the MASTER? I would uncomment them and would move the ending form tag to above the </body> tag as well.
 
I see I made a mistake in my explanation, the MASTERPAGE is my default.aspx.

c8msm:
If i remove the form tag completely i get:
"System.Web.HttpException: Control 'ctl00_CPHContent_TextBox1' of type 'TextBox' must be placed inside a form tag with runat=server"
when I leave the formtag i get: "System.Web.HttpException: A page can have only one server-side Form tag"
or am I doing something wrong?

henslecd:
Yes, I use ASP.NET 2.0, the reason i commented the form tag in my masterfile is because if I dont I get: "System.Web.HttpException: A page can have only one server-side Form tag"

if you could help me out that would be great! perhaps you can use my sourcecode.
thx
 
Just remove the form tags completely from the control. Then, on the MASTERPAGE aspx page, place a form tag with runat=server below <body> and the closing form tag above </body>.
 
I am basing my experience on version 1.1 of the framework but if you use a usercontrol you simply omit the form tags on the user control and include it on each page as per normal.

When the page renders the HTML of the usercontrol is placed within the HTML of the page and therefore within the form tag that belongs to the page.

If this is not the case in version 2.0 and when using master pages then I'm afraid I have no further knowledge on it.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Oke, the problem is solved. As you could see I had the form tag commented in my masterfile (ASP 2.0), however for some reason it still got parsed as code. I've now completely removed them and back in business. thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top