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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am trying to color text boxes in a form 1

Status
Not open for further replies.

Gzk2010

Programmer
Aug 17, 2010
48
US
I am trying to color text boxes in a form and I get below error when run web page...

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

Exception Details: System.Web.HttpException: A page can have only one server-side Form tag."


my code behind:
foreach (Control c in frmBillingandShipping.Controls)

{
if (c.GetType() == typeof(TextBox))
{
TextBox t = (TextBox)c;
t.BackColor = System.Drawing.Color.AliceBlue;
t.ReadOnly = false;
}
}

my aspx page (top portion):

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="BillingandShipping.aspx.cs" Inherits="Gzk2012.ShoppingCart.BillingandShipping" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%--<form id="frmBillingandShipping" method="post" runat="server">--%>
...
</form>
</asp:Content>



I understand the master page has a form tag, how to get around this?
Thanks
 
You can't at least not with the webforms model.. might be possible with MVC but not sure. Jason who posts here often can answer that for you.
 
Thanks JBenson001.

Clearly the line I post above was not commented out at time the exception was thrown. <%--<form id="frmBillingandShipping" method="post" runat="server">--%>
 
webforms can have 1 webforms form element and multiple html form elements. However form elements cannot be nested so you can't do this
Code:
<form id="form1" runat="server">
   <form id="sub-form1">
   </form>
   <form id="sub-form2">
   </form>
</form>
At least that's my understanding. Mark (cas8m) told me about that nuance. When I worked with webforms i only ever used the single webcontrol form element.

html does allow for multiple non-nested forms
Code:
<body>
   <form id="form1" action="/dothis" method="post">
   </form>
   <form id="form2" action="/dothat" method="post">
   </form>
   ...
   <form id="formN" action="/fpp" method="post">
   </form>
</body>
using an view engine that works with pure html rather than webforms servercontrol html tags allows for this kind of setup without any friction.

I'll stop short there, but if you're interested I would start researching the concepts of MVC (model view controller)

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top