4.2. Submitting a Form to a Different Page
Problem
You need to submit the information on one page—a form, for example—to another. You might want to do this to use one page to collect form data and a second page to process it.
Tip
The default operation for ASP.NET is to submit the form to the same page. Submitting the form to a different page—i.e., performing cross-page posting—requires some coding gymnastics in ASP.NET 1.x, explained in some detail in the first edition of the ASP.NET Cookbook:
Using the
Server.Transfermethod in a button click event handler in the code-behind of the first page to transfer control to a second page, after saving the contents of the first in session scope.Using the
Server.Transfermethod in a button click event handler in the code-behind of the first page to transfer control, along with the form contents in theViewState, to the second page.
In ASP.NET 2.0, however, performing cross-page posting is easier because you can now accomplish it by setting the PostBackUrl button property.
Solution
Use the cross-page posting functionality added to ASP.NET 2.0 to submit a form to a different page.
In the .aspx file of the first page, set to the URL of the desired page the PostBackUrl property of the button that will initiate the submission of the form to another page. No special code is required in the code-behind of the first page to support cross-page posting.
In the code-behind of the second page, use the .NET language of your choice to:
Check to verify that page ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access