Form tag on ASP.net page

This is a common problem, when you want to have a non-postback form to a 3rd party site (like a PayPal button, for example).

The problem occurs because HTML doesn't let you have form within a form, and most ASP.NET pages have a <form runat="server" /> "high up" in the HTML (or in the Master page).

My favorite solution is to hide the "high up" form tag, while still showing all of the content. Then you can feel free to dump any tags you want in the body. If you do this dynamically you can choose on a page-by-page basis which pages have custom forms.

I created a class called GhostForm.cs to handle this. You can read all about it here:

http://jerschneid.blogspot.com/2007/03/hide-form-tag-but-leave-content.html


There can only be one form on the page (the asp form); you have to use that form somehow.

To clarify, there can only be one form processed.


Not with webforms, no. You have to work within the one, full page form by using an event handler connected to a Button to LinkButton. Fortunately, it's pretty easy to do:

foo.aspx:

...
<asp:TextBox id="txtFoo" runat="server" />
<asp:Button id="btnFoo" runat="server" onclick="btnFoo_Click />
...

foo.aspx.cs:

...
protected void btnFoo_Click(object sender, EventArgs e)
{
    string s = txtFoo.Text;
    // do something with s
}
...

Tags:

Asp.Net