3.4. Simulating Multipage Forms
Problem
You want to create a form that appears, from
the
user’s prospective, to consist of multiple pages,
while keeping all of your code in one .aspx
file
and the code-behind that accompanies it.
Solution
Create one ASP.NET page. Use panels to separate the HTML for each of
the “virtual” pages you wish to
display, and simulate a multipage form by enabling one panel at a
time. The output of a typical three-page form is shown in Figures
Figure 3-1 through Figure 3-3.
Example 3-13 through Example 3-15 show the .aspx
and
code-behind files for an application that implements this solution.
Figure 3-1. Multipage form output (page 1)
Figure 3-2. Multipage form output (page 2)
Figure 3-3. Multipage form output (page 3)
Discussion
In classic ASP, a series of questions or prompts, such as those on a
survey or wizard, are typically implemented using multiple ASP pages
with each submitting to the next in turn. ASP.NET allows you to
submit a form to itself, which means that you have to rethink how to
implement a survey, wizard, or traditionally multipart form. The
solution we advocate involves defining multiple panels on a single
form with the ASP:Panel
control, and showing ...
Get ASP.NET Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.