Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - <form runat=server> Tag in a MasterPage environment

 
Thread Tools Search this Thread
Old 04-21-2006, 11:10 PM   #1
Default <form runat=server> Tag in a MasterPage environment


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.


=?Utf-8?B?QWxleCBNYWdoZW4=?=
  Reply With Quote
Old 04-21-2006, 11:37 PM   #2
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
 
Posts: n/a
Default RE: <form runat=server> Tag in a MasterPage environment

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.

  Reply With Quote
Old 04-22-2006, 12:04 AM   #3
=?Utf-8?B?QWxleCBNYWdoZW4=?=
 
Posts: n/a
Default RE: <form runat=server> Tag in a MasterPage environment

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.

  Reply With Quote
Old 04-24-2006, 01:58 AM   #4
Steven Cheng[MSFT]
 
Posts: n/a
Default RE: <form runat=server> Tag in a MasterPage environment

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.)

  Reply With Quote
Old 04-27-2006, 12:03 PM   #5
Steven Cheng[MSFT]
 
Posts: n/a
Default RE: <form runat=server> Tag in a MasterPage environment

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.)

  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump