tags:

views:

41

answers:

2

Tearing my hair out here trying to implement a pretty simple form inside a .NET page.

The form looks like this:

<form action="http://domain.com/subscribe.tml" method="POST"> 
<p><input name="email" type="text" /></p> 
<p><input type="image" src="/images/ui/btn-getfreereport.gif" alt="Signup" /> </p> 
<input type="hidden" value="one_hello" name="confirm" /> 
<input type="hidden" value="F" name="showconfirm" /> 
</form>

I feel pretty stupid because I've spent two years trying to figure out how to do this. The only luck I've had is using Javascript, but now that I want two of these forms, that Javascript isn't working.

Leaving the plain <form> code in there actually seems to work, except for in IE, where it adds a ~200px margin underneath the </form> (and using CSS to remove the margin and padding doesn't help).

I read about the HtmlForm class, but can't find examples of how to send data for the form above.

A: 

in .net you cannot nest forms. Try putting your form outside the <form runat="server" > tags.

skyfoot
I must be missing something then ... how do I place the forms within the page if they have to be outside of the <form runat="server"> tag? Do you mean I close that tag and then reopen it?
Jon
A: 

You can have one form in the asp.net page and seperate multiple contact form(NOT THE ASP.NET FORM Element,I mean the general term "Form") with either DIV's or PANEL's.

You can have each "Send/Save" button for each form(i mean in general,not asp.net form) to send the contact info to someone or save it to the DB.

<body>
<form id="form1" runat="server">
 <div id="divContactForm1">
   <h1>My First form is here</h1>
   Name <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
   <asp:Button ID="btnForm1" runat="server" Text="Save" onclick="btnForm1_Click" />
 </div>
 <div id="divContactForm2">
     <h1>My Second form is here</h1>
     Email
     <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
     <asp:Button ID="btnForm2" runat="server" Text="Save" onclick="btnForm2_Click" />
 </div>
</form>
</html>

and in the codebehind

   protected void btnForm1_Click(object sender, EventArgs e)
    {
        //Read textbox value and do whatever you want
    }

    protected void btnForm2_Click(object sender, EventArgs e)
    {
        //Read textbox value  here and do whatever you want
    }
Shyju
Can you explain what you mean by separate them with div's?
Jon
@Jon:Answer updated with the sample code
Shyju
@Shyju: Thanks, but that isn't using actual <form> code. I need to post several fields to another URL, which is where my confusion is. I can't find anything that explains clearly how to take a form and post it somewhere else (like Paypal). I might just use the API instead.
Jon