..
Often, when sending data through a form, it is preferable not to present the user with a very long form in order not to discourage him from compiling a seemingly long and complex for this purpose, therefore, it is advisable to divide your form in several stages to be presented in sequence.
Generally, you use to associate - in each block - the data consistent, such as a registration form pottrebbe be divided as follows: username, password and email in the first block of the block, the personal data in another block and so on.
Thanks to the built-in functions. NET Framework, ASP.NET is very simple in achieving such a system in which, within the same page, the following will happen:
We come to a practical example, starting from the HTML, properly constructed through the server controls. NET:
<form runat="server"> <p> <asp:literal id="numero" runat="server"/> </ p> <p> <asp:textbox id="uno" runat="server"/> </ p> <p> <asp:Button runat="server" id="c1" text="Continua" onclick="Step1"/> </ p> <p> <asp:textbox id="due" runat="server"/> </ p> <p> <asp:Button runat="server" id="c2" text="Continua" onclick="Step2"/> </ p> <p> <asp:textbox id="tre" runat="server"/> </ p> <p> <asp:Button runat="server" id="c3" text="Conferma" onclick="Step3"/> </ p> <p> <asp:literal id="messaggio" runat="server"/> </ p> </ Form>
In our example, each step consists of a single field and one submit button: all the buttons will take the next step, but the last material that will lead to data management.
We note that the beginning and end we use two text elements: the first is used to indicate the number of the current step, while the bottom one will show the error messages and confirmation for transactions.Let VB.NET code:
<script runat="server" Language="VB">
Private Sub Page_Load (sender As Object, e As System.EventArgs)
If Page.IsPostBack = False Then
numero.Text = "Step 1"
due.Visible = False
tre.Visible = False
c2.Visible = False
c3.Visible = False
End If
End Sub
Private Sub Step1 (sender As Object, e As System.EventArgs)
If uno.Text = "" Then
messaggio.Text = "Required!"
Exit Sub
End If
numero.Text = "Step 2"
uno.Visible = False
due.Visible = True
c1.Visible = False
c2.Visible = True
messaggio.Text = ""
End Sub
Private Sub Step2 (sender As Object, e As System.EventArgs)
If due.Text = "" Then
messaggio.Text = "Required!"
Exit Sub
End If
numero.Text = "Step 3"
due.Visible = False
tre.Visible = True
c2.Visible = False
c3.Visible = True
messaggio.Text = ""
End Sub
Private Sub Step3 (sender As Object, e As System.EventArgs)
If tre.Text = "" Then
messaggio.Text = "Required!"
Exit Sub
End If
numero.Text = "Result"
tre.Visible = False
c3.Visible = False
End Sub
</ Script>
First, the page load event occurred PostBack to verify that the content of this page is not "distorted". Inside, show the message to appear as the title of the first step and hide all the elements of the next steps.
Then we have the routines that verify the completion of the current field, hiding the previous step and the next show.
Only the last step will not show, of course, a next step, but will perform data management: in our example, simply show the video data.
I leave the reader to do the following: to create for each step of the Label server side and use it to hide all the fields in a single step (eg name, surname, username, password, email, website).
| |
ASP (Advanced)
Full course for creating dynamic Web sites. From 39 €. |
| |
ASP.NET (Course)
Full course for building Web applications from 49 €. |
| |
SQL and Database (Course)
Create and manage relational databases. From 39 €. |