By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,694 Members | 2,122 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,694 IT Pros & Developers. It's quick & easy.

<form runat=server> Tag in a MasterPage environment

P: n/a
I have a master page which contains a general page framework and also
contains a <form runat=server> around most of the content of the page. Inside
that <form> tag is a ContentPlaceholder.

I then create an ASPX which is tied to that MasterPage and in it a put a
bunch of form fields and an <asp:Button />. When I try to run the page, I
get...

"Control 'ctl00_BodyCPH_ctl00' of type 'Button' must be placed inside a form
tag with runat=server."

So I tried outing a form inside the ASPX page as well and I got a different
error...

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

So does this mean that I have to have the FORM tag inside the ASPX page and
cannot have it be in the MASTER page? That seems weird, especially because
when you use VS to create a MasterPage, it opens with a form tag already
inside it.
Apr 21 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Does your page have a set of:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
.....
</asp:content>

tags, and are all your controls inside these? You should only have the Form
tags in the MasterPage.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Alex Maghen" wrote:
I have a master page which contains a general page framework and also
contains a <form runat=server> around most of the content of the page. Inside
that <form> tag is a ContentPlaceholder.

I then create an ASPX which is tied to that MasterPage and in it a put a
bunch of form fields and an <asp:Button />. When I try to run the page, I
get...

"Control 'ctl00_BodyCPH_ctl00' of type 'Button' must be placed inside a form
tag with runat=server."

So I tried outing a form inside the ASPX page as well and I got a different
error...

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

So does this mean that I have to have the FORM tag inside the ASPX page and
cannot have it be in the MASTER page? That seems weird, especially because
when you use VS to create a MasterPage, it opens with a form tag already
inside it.

Apr 21 '06 #2

P: n/a
Okay so I think I've figured out what my problem was but I still have a
question about it...

Here's the hierarchy of my MASTER PAGE:
<body>
<form id="MainFrm" runat="server">

<!--non-server form for some other fields...-->
<form method=get action="xyz.aspx"><!--NOTE: NOT RUNAT=SERVER-->
</form>

<asp:contentplaceholder id="BodyCPH" runat="server">
</asp:contentplaceholder>
</form>
</body>

So it turns out that this error ocurrs when I have the non runat=server
<form> INSIDE the "main" <form runat=server> that covers the whole page. If I
remove this, everything works fine.

But the problem is, I need (I like) this old-fashion HTML form inside my
master-page because it posts back to a different page and is sort of
encapsulated. Is there a way for me to keep it? And why is it a problem when
it's not a SERVER form?

Alex

"Peter Bromberg [C# MVP]" wrote:
Does your page have a set of:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
....
</asp:content>

tags, and are all your controls inside these? You should only have the Form
tags in the MasterPage.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Alex Maghen" wrote:
I have a master page which contains a general page framework and also
contains a <form runat=server> around most of the content of the page. Inside
that <form> tag is a ContentPlaceholder.

I then create an ASPX which is tied to that MasterPage and in it a put a
bunch of form fields and an <asp:Button />. When I try to run the page, I
get...

"Control 'ctl00_BodyCPH_ctl00' of type 'Button' must be placed inside a form
tag with runat=server."

So I tried outing a form inside the ASPX page as well and I got a different
error...

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

So does this mean that I have to have the FORM tag inside the ASPX page and
cannot have it be in the MASTER page? That seems weird, especially because
when you use VS to create a MasterPage, it opens with a form tag already
inside it.

Apr 22 '06 #3

P: n/a
Hi Alex,

Nice to see you again:).

Regarding on the <form> issue you mentioned, here are some of my
understanding and suggestion:

Html <form> element can be put in the body of html pages and html page does
support multiple <form> elements, however they can not be nested each
other, you can find the detailed description from the W3C html
specification:

#The FORM element
http://www.w3.org/MarkUp/html3/forms.html

And as for ASP.NET web form page, it is based on a single server-side form
element which contains all the controls inside it, so generally we do not
recommend that we put multiple <form> elements. However, this is still
supported in ASP.NET page(master page) and I think the problem in your
master page should be caused by the unsupported nested <form> element, and
multiple <form> in the same level should be ok. e.g:

========================
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MForm.master.cs"
Inherits="App_Masters_MForm" %>

<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
<form id="form2" action="http://www.asp.net">
<input name="txtf2" type="text" />
</form>
</body>
</html>

==============================

In addition, if what you want to do through multiple forms is just make our
page posting to multiple pages, I think you can consider using the new
feature for cross-page posting in ASP.NET 2.0. This can help us use button
controls to postback to different pages without having multpile forms on
the page:

#Cross-Page Posting in ASP.NET Web Pages
http://msdn2.microsoft.com/en-us/lib...39(VS.80).aspx

http://msdn2.microsoft.com/en-us/lib...40(VS.80).aspx

Hope this helps. Please feel free to post here if there is anything else we
can help.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Apr 24 '06 #4

P: n/a
Hi Alex,

How are you doing on this or does my last reply helps you some? If there's
still anything we can help, please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Community Support
==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Apr 27 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.