As we know, Asp.Net not allows more than one <form runat="server"> tag in webForm (page). What if we need 2 <form> tags on the same page?
In this post, i will explain how to maintain 2 <form> tags in a single webForm.
Let Default.aspx is the main page, write the usual Asp.Net form tag:
<form id="form1" runat="server">
and then write another HTML form tag (without runat="server" attribute):
<form id="form2" action="UILessPage.aspx" method="post">
in the same page.
The trick is form2 posts its data to "UILessPage.aspx" instead of "Default.aspx", because, we want data from form2 be handled separately instead of mingling with Default.aspx code.
This makes easy to understand and maintain the Form data. The UILessPage.aspx page contains no UI (markup) for itself, its job is only handling the form2 data, we can even make this page not accessible if accessed directly from browser.
- The Form2 should contain only HTML controls .
- Form1 can contain WebServer controls.
Please download and check the code to understand how to retrieve the submitted data from form2. I used the "Request.Form[CtrlName]" to get the HTML control values from form2.
download the code files as zip from here.