Creating multi-steps input forms

Creating multi-steps input forms

In a typical user registration form, you may ask for quite a lot of data, such as the first and last name, full address, phone and fax numbers, e-mail address, newsletters subscriptions and other data for the site personalization. All this data shouldn’t the asked in a single step, because a long list of input controls would probably discourage an user. It would be better to divide the form in a few steps, at least 2 or 3, so that the user perceives the process as simpler (even though they will ultimately fill in the same input controls anyway, of course). To do this, the typical ASP approach is to write separate pages, and pass the control from one to the following page. However, this is not very straighforward for the programmer, because he must find a way to pass to the following page all the user data typed into the current form, so that at the end of the process the last page will get all the inserted user data. Passing user data from a page to another is usually done with parameters in the querystring or with session variables, but in this case you can avoid these methods at all, and use a totally different approach to create multi-steps input forms. You can create two or three panels on the ASPX page, and show/hide them (by means of the Visible property) according to the current step index (that in increased/decreased by clicking two buttons). The Panel control acts like a container control, so you place the input controls of each steps inside the respective panel. Here’s how you define the panels in the ASPx page:

Note that only the first panel is visible by default, the other two are hidden. When the user presses the Next button, the first panel and its child controls will be made invisible, and the second panel will be shown with its child controls. The process is similar for the third step, where also a Finish button will be made visible. The great thing of this approach is that you don’t need to have a separate page for each step, and so don’t need to pass values from a page to another. Also consider that when a control has its server-side Visible property set to False its content is not sent to the client browser at all, so if you use this method you won’t be sending the HTML code for the whole page, but just the HTML for the current step. Here’s how you manage the whole process from the code-behind class:

Public Class InputForm : Inherits System.Web.UI.Page    Protected FirstStep As System.Web.UI.WebControls.Panel    Protected SecondStep As System.Web.UI.WebControls.Panel    Protected ThirdStep As System.Web.UI.WebControls.Panel    Protected ThirdStep As System.Web.UI.WebControls.Panel    Protected Previous As System.Web.UI.WebControls.Button    Protected Finish As System.Web.UI.WebControls.Button    Protected Next As System.Web.UI.WebControls.Button    Private  Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)        If Not Me.IsPostBack Then            ' the first time the page is loaded, set the current step index to 1            ViewState("CurrentPage") = 1        End If    End Sub    Private  Sub Previous_Click(ByVal sender As Object, _        ByVal e As System.EventArgs)        ' Previous button clicked, decrease the step index by 1        ShowPage(Integer.Parse(ViewState("CurrentPage").ToString()) - 1)    End Sub    Private  Sub Next_Click(ByVal sender As Object, ByVal e As System.EventArgs)        ' Next button clicked, increase the step index by 1        ShowPage(Integer.Parse(ViewState("CurrentPage").ToString()) + 1)    End Sub    Private  Sub ShowPage(ByVal page As Integer)        ' save the current step index in the ViewState        ViewState("CurrentPage") = page        ' show/hide the panels and the Next/Previous/Finish buttons according         ' to the current step index        Select Case page            Case 1                Previous.Visible = False                Next.Visible = True                FirstStep.Visible = True                SecondStep.Visible = False                Exit Sub            Case 2                Previous.Visible = True                Next.Visible = True                Finish.Visible = False                FirstStep.Visible = False                SecondStep.Visible = True                ThirdStep.Visible = False                Exit Sub            Case 3                Next.Visible = False                Previous.Visible = True                     Finish.Visible = True                SecondStep.Visible = False                ThirdStep.Visible = True                Exit Sub        End Select    End Sub    Private  Sub Finish_Click(ByVal sender As Object, _        ByVal e As System.EventArgs)        ' When the Finish button is clicked, process the user input    End SubEnd Class

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing