How to Handle Multiple Forms on a Page

F

FayHuang

Hi,

I am very new beginner to ASP.NET, but I inherited this ASP.NET
project from a person who left our company. So I hope that my problem
is fairly simple to solve.

Here is the background to the problem: I am working on the "Contact
Us" page for an e-commerce website. This page consists of the main
section of the page (Contact Us fields like First Name, Last Name,
etc.) and navigation sections (Navigation bar, Search textbox,
drop-down box & button, Subscribe now textbox & button). The side,
top, bottom navigation and Search fields have been put into separate
controls.

On the aspx page, I have the following defined:
<%@ Page language="c#" Codebehind="Contact.aspx.cs"
AutoEventWireup="false" Inherits="AOpenCenter.Contact.Contact" %>
<%@ Register TagPrefix="AOC" TagName="Footer"
Src="/controls/Footer.ascx" %>
<%@ Register TagPrefix="AOC" TagName="SearchBox"
Src="/controls/SearchBox.ascx" %>
<%@ Register TagPrefix="AOC" TagName="LeftNav"
Src="/controls/LeftNav.ascx" %>
<%@ Register TagPrefix="AOC" TagName="TopNav"
Src="/controls/TopNav.ascx" %>
<%@ Register TagPrefix="AOC" TagName="Header"
Src="/controls/Header.ascx" %>
<%@ Register TagPrefix="AOC" TagName="HeadTag"
Src="/controls/HeadTag.ascx" %>

I have a button that I want to submit my contact us fields.
Here is the button definition:
<asp:ImageButton ID="ContactUsButton" onClick="OnClick_Submit"
imageURL="/images/btnSubmit.gif" Runat="server" />

OnClick_Submit is defined in the code behind:
protected void OnClick_Submit (object source,
System.Web.UI.ImageClickEventArgs e)
{
if (Page.IsValid)
{
TopLabel.Text = "Success!";
}
else
{
TopLabel.Text = "Failed!";
}
}

I am able to compile the solution with no problems.

Problem: When I try to bring up the page, the page displays an error
that "'ASP.Contact_aspx' does not contain a definition for
'OnClick_Submit'". But OnClick_Submit is clearly defined in the
code-behind. So I'm guessing that there is some conflict with the
other controls/forms on the page. Does someone know how I should go
about debugging/fixing this problem?

Thanks!
 
S

Steve C. Orr [MVP, MCSD]

You can only have one visible server form on the page at a time.
So you could have more than one server form as long as you only show one at
a time.
Or you can have more than one form visible on your page at a time, but only
one of them can be a server form (i.e. with the runat=server attribute.)
Server forms only support posting back to themselves (not to other pages.)

This will all become more flexible in .NET version 2.
 
V

vMike

FayHuang said:
Hi,

I am very new beginner to ASP.NET, but I inherited this ASP.NET
project from a person who left our company. So I hope that my problem
is fairly simple to solve.

Here is the background to the problem: I am working on the "Contact
Us" page for an e-commerce website. This page consists of the main
section of the page (Contact Us fields like First Name, Last Name,
etc.) and navigation sections (Navigation bar, Search textbox,
drop-down box & button, Subscribe now textbox & button). The side,
top, bottom navigation and Search fields have been put into separate
controls.

On the aspx page, I have the following defined:
<%@ Page language="c#" Codebehind="Contact.aspx.cs"
AutoEventWireup="false" Inherits="AOpenCenter.Contact.Contact" %>
<%@ Register TagPrefix="AOC" TagName="Footer"
Src="/controls/Footer.ascx" %>
<%@ Register TagPrefix="AOC" TagName="SearchBox"
Src="/controls/SearchBox.ascx" %>
<%@ Register TagPrefix="AOC" TagName="LeftNav"
Src="/controls/LeftNav.ascx" %>
<%@ Register TagPrefix="AOC" TagName="TopNav"
Src="/controls/TopNav.ascx" %>
<%@ Register TagPrefix="AOC" TagName="Header"
Src="/controls/Header.ascx" %>
<%@ Register TagPrefix="AOC" TagName="HeadTag"
Src="/controls/HeadTag.ascx" %>

I have a button that I want to submit my contact us fields.
Here is the button definition:
<asp:ImageButton ID="ContactUsButton" onClick="OnClick_Submit"
imageURL="/images/btnSubmit.gif" Runat="server" />

OnClick_Submit is defined in the code behind:
protected void OnClick_Submit (object source,
System.Web.UI.ImageClickEventArgs e)
{
if (Page.IsValid)
{
TopLabel.Text = "Success!";
}
else
{
TopLabel.Text = "Failed!";
}
}

I am able to compile the solution with no problems.

Problem: When I try to bring up the page, the page displays an error
that "'ASP.Contact_aspx' does not contain a definition for
'OnClick_Submit'". But OnClick_Submit is clearly defined in the
code-behind. So I'm guessing that there is some conflict with the
other controls/forms on the page. Does someone know how I should go
about debugging/fixing this problem?

Thanks!

I am not familiar with C but in VB you need to add in your code behind page
the following

Protected WithEvents ContactUsButton as ImageButton

There is probably something similar in C

hope that helps
 
T

Tim Mackey

hi Fay,
i think you need to make the Submit_OnClick public instead of protected.
let me know if this fixed it.

tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top