473,668 Members | 2,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<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 ContentPlacehol der.

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
4 13320
Does your page have a set of:

<asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder1"
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 ContentPlacehol der.

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
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.asp x"><!--NOTE: NOT RUNAT=SERVER-->
</form>

<asp:contentpla ceholder id="BodyCPH" runat="server">
</asp:contentplac eholder>
</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" ContentPlaceHol derID="ContentP laceHolder1"
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 ContentPlacehol der.

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
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_M asters_MForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:contentpla ceholder id="ContentPlac eHolder1" runat="server">
</asp:contentplac eholder>
</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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1755
by: Hai Nguyen | last post by:
Hi all I have a several User Controls which require this tag: "<form runat="server">. I tried to have all of these user user controls on the same web page. It kept giving me an error :""A page can have only one server-side Form tag" Is there a way to go around this?
1
4274
by: jason | last post by:
Pardon the newbie question... What's the difference between (asp.net)VB code inside one versus the other. And why have both?
4
9952
by: Matthew Louden | last post by:
It happend to me more than once. When I create web controls or move the positions in VS.NET, I encountered the following run-time errors: It doesn't matter what controls I create, the following 'checkbox' control is just an example. Control 'CheckBox1' of type 'CheckBox' must be placed inside a form tag with runat=server. Description: An unhandled exception occurred during the execution of the current web request. Please review the...
3
1205
by: Roshawn | last post by:
Hi, Is it possible for a <form> tag that doesn't have the "runat='server'" attribute to contain HTML controls that do have the "runat='server'" attribute? The reason I ask is that all examples I've seen place ASP.NET controls (which have the "runat='server'" attribute by default) inside a <form> tag that contains the "runat='server'" attribute also. Thanks, Roshawn
4
4825
by: George | last post by:
I'm using .NET framework 1.1 and VS.NET 2003 for a aspx web form. There is a DropDwonList on the page and its SelectedIndexChanged event is fired to the server normally, until when I add another form "FormDummy" onto the main form, and then the event no longer fires again when the user change the value of the drop down list. Can anybody help ? Thanks so much! The aspx code is as follows:
7
6278
by: Alex Maghen | last post by:
I have some client-side JavaScript that I want to run whenever a pulldown <SELECT> is changes on th client. I'm trying to do this as follows... <select id="MyPulldown" onchange="handleProblemChange();" runat="server"> If I do this, I get client-side javascript errors because the id "MyPulldown" doesn't exist. It's been mangled into this crazy-named thing that I can't use. How do I fix this so that the ID that I give it ends up being...
4
2904
by: Kevin Blount | last post by:
bit long winded this one, so stick with me: I'm trying to create a form that can go to one of 3 places, depending on various elements. My form control looks like this: <form runat="server" ID="myForm" method=POST> so, first thing: how can I dynamically set the "Action" parameter? I know that with <asp:HiddenField...for example, I have to do something like this:
1
2424
by: mark4asp | last post by:
<form runat="server"automatically adds <divtag to code contained within. Is there a way to stop that? Mixing block-level elements with inline-level elements messes up the HTML becasuse that is invalid for a strict implementation. <spanis in-line-level and <divis block-level. I don't want to mix up <span> and <div> I'm using an <asp:Buttonhere because when it switches to the URL I need to check that the user is in the correct role -...
19
2138
by: Coward 9 | last post by:
HI, I saw in an example hello.aspx, there is a <form tagbeing used like <form runat="server> I search all html tag references and could NOT find "runat" attributes for <formtag. which reference should I use in order to find that?
0
8462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8381
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8893
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8656
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7401
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4205
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2791
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.