Digital Lightcraft
Digital Lightcraft

Reputation: 465

a page can have only one server-side form tag.. but I need 2

I have this at the bottom of my page:

<form id="Login" method="post" runat="server">
<span class="MenutextWhite">You are logged in as 
<asp:Label ID="lblUsername" Runat="server"></asp:Label> 
- not you?&nbsp;&nbsp;</span>
<asp:LinkButton CssClass="MenutextWhite" ID="btnLogout" Runat="server" Text="Log out"
OnClick="Logout_Click" tip="click here to log out"> 
</asp:LinkButton>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href = "admin.aspx"
class="MenutextWhite">Admin</a>&nbsp;&nbsp;&nbsp;
</form> 

this deals with displaying who the user is and giving access to the admin section and logoff button. (I am not using masterpages)

However further up the page, in the main content area, I need another control (freetextbox)

How can I get around this single form only problem?

Upvotes: 2

Views: 2136

Answers (3)

Crab Bucket
Crab Bucket

Reputation: 6277

As Jason Meckley says - you can't. But in ASP.Net forms I've never needed it.

You have two buttons for two different parts of the form - so you will have 2 different click handlers so can take two different actions

protected void ptnFormPart1_Click(object sender, EventArgs e)
{
   //.. action 1
}

protected void ptnFormPart1_Click(object sender, EventArgs e)
{
   //.. action 2
}

Therefore you don't need two different forms with two different actions

Upvotes: 1

Digital Lightcraft
Digital Lightcraft

Reputation: 465

Solved! The 2 Forms that I required were in different DIV's.

as i can only have one form, I put the tags just inside the - outside all contents.

Now everything works ok.

Upvotes: 0

Jason Meckley
Jason Meckley

Reputation: 7591

you can only have one form with a server side tag. however you can have as many html forms (without the runat=server) tags. The runat=server tag allows the webforms page life cycle and view stuff to work.

if you want a more traditional web development experience don't use webforms. Instead use an mvc framework (FUBU, Monorail, MSMVC, etc)

Upvotes: 1

Related Questions