Reader Level:
ARTICLE

Registration Form using Two Webpages in VB.NET

Posted by Satyapriya Nayak Articles | Visual Basic .NET November 09, 2012
In this article we will make a register page and working with it by different pages.
  • 0
  • 0
  • 7393
Download Files:
 

In this article we will do a register page, but here in one form we will not insert all the information, rather we will insert some information in one page and some other information's in the next page but the first information we have inserted will be show in the second page and then we will click register button to have a complete registration and a success page will display containing the Full name of the user who have already registered.

Program

FirstForm.aspx code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="FirstForm.aspx.vb"Inherits="FirstForm" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1
transitional.dtd">
 
<
html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<
body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Label ID="Label1" runat="server" Text="First Name" Width="160px" 
            Font-Bold="True"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server" Width="200px"></asp:TextBox>

        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
            ControlToValidate="TextBox1" ErrorMessage="Name Required"></asp:RequiredFieldValidator>
        <br />
        <asp:Label ID="Label2" runat="server" Text="Email" Width="160px" 
            Font-Bold="True"></asp:Label>

        <asp:TextBox ID="TextBox2" runat="server" Width="200px"></asp:TextBox>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
            ControlToValidate="TextBox2" ErrorMessage="Invalid Email" 
            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
            ControlToValidate="TextBox2" ErrorMessage="Email Required"></asp:RequiredFieldValidator>
        <br />
        <asp:Label ID="Label3" runat="server" Text="Mobile No" Width="160px" 
            Font-Bold="True"></asp:Label>
        <asp:TextBox ID="TextBox3" runat="server" Width="200px"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
            ControlToValidate="TextBox3" ErrorMessage="Mobile No. Required"></asp:RequiredFieldValidator>
        <br />
        <asp:Label ID="Label4" runat="server" Text="Country" Width="160px" 
            Font-Bold="True"></asp:Label>
    
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem>India</asp:ListItem>
            <asp:ListItem>usa</asp:ListItem>
            <asp:ListItem>uk</asp:ListItem>
            <asp:ListItem>Nepal</asp:ListItem>

            <asp:ListItem>Srilanka</asp:ListItem>
            <asp:ListItem>Australia</asp:ListItem>
            <asp:ListItem>Germany</asp:ListItem>
        </asp:DropDownList>
    
        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
            ControlToValidate="DropDownList1" ErrorMessage="Country Required"></asp:RequiredFieldValidator>
    
    </div>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
        Text="Register continue to next page" Font-Bold="True" />
    </form>
    </body>
</html>

FirstForm.aspx.vb code

Imports System.Data.SqlClient
Imports System.Data
Partial Class FirstForm
    Inherits System.Web.UI.Page
    Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString"
.ToString()
    Dim con As New SqlConnection(strConnString)
    Dim sqlda As SqlDataAdapter
    Dim com As SqlCommand
    Dim ds As DataSet
    Dim str As String
    Dim url As String
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) HandlesButton1.Click
        url = "SecondForm.aspx?name=" & TextBox1.Text & "&email=" & TextBox2.Text &"&mobileno=" & TextBox3.Text & "
&country="
 & DropDownList1.SelectedItem.Text
        Response.Redirect(url)
    End Sub
End Class

SecondForm.aspx code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="SecondForm.aspx.vb"Inherits="SecondForm" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1
transitional.dtd">
 

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<
body>
    <form id="form1" runat="server">
    <div>
    <asp:Label ID="Label1" runat="server" Text=" Email:*" Width="160px" 
            Font-Bold="True"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server" Width="200px"></asp:TextBox>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
            ControlToValidate="TextBox1" ErrorMessage="Invalid email" 
            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
        <br />
        <asp:Label ID="Label2" runat="server" Text=" Password:*" Width="160px" 
            Font-Bold="True"></asp:Label>
        <asp:TextBox ID="TextBox2" runat="server" Width="200px" TextMode="Password"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
            ControlToValidate="TextBox2" ErrorMessage="Password Required"></asp:RequiredFieldValidator>
        <br />
        <asp:Label ID="Label3" runat="server" Text=" Confirm Password:*" Width="160px" 
            Font-Bold="True"></asp:Label>
        <asp:TextBox ID="TextBox3" runat="server" Width="200px" TextMode="Password"></asp:TextBox>

        <asp:CompareValidator ID="CompareValidator2" runat="server" 
            ControlToCompare="TextBox2" ControlToValidate="TextBox3" 
            ErrorMessage="Password mismatch"></asp:CompareValidator>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
            ControlToValidate="TextBox3" ErrorMessage="ConfirmPassword Required"></asp:RequiredFieldValidator>
        <br />
        
        <asp:Label ID="Label4" runat="server" Text="First Name:*" Width="160px" 
            Font-Bold="True"></asp:Label>
        <asp:TextBox ID="TextBox4" runat="server" Width="200px"></asp:TextBox><br />

        <asp:Label ID="Label5" runat="server" Text=" Last Name:*" Width="160px" 
            Font-Bold="True"></asp:Label>
        <asp:TextBox ID="TextBox5" runat="server" Width="200px"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
            ControlToValidate="TextBox5" ErrorMessage="Last Name Required"></asp:RequiredFieldValidator>
        <br />
        <asp:Label ID="Label6" runat="server" Text="Mobile Number: *" Width="160px" 
            Font-Bold="True"></asp:Label>
        <asp:TextBox ID="TextBox6" runat="server" Width="200px"></asp:TextBox><br />
        <asp:Label ID="Label7" runat="server" Text="You have selected: *" Width="160px" 
            Font-Bold="True"></asp:Label>
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>
        <br />
    </div><br />
    <asp:Button ID="Button1" runat="server" Text="Confirm Register" onclick="Button1_Click" 
        Font-Bold="True" />
    </form>
</body>
</
html>

SecondForm.aspx.vb code

Imports System.Data.SqlClient
Imports System.Data
Partial Class SecondForm
    Inherits System.Web.UI.Page
    Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString".ToString()
    Dim con As New SqlConnection(strConnString)
    Dim sqlda As SqlDataAdapter
    Dim com As SqlCommand
    Dim ds As DataSet
    Dim str As String
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) HandlesMe.Load
        TextBox4.Text = Request.QueryString("name")
        TextBox1.Text = Request.QueryString("email")
        TextBox6.Text = Request.QueryString("mobileno")
        DropDownList1.Items.Add(Request.QueryString("country"))
    End Sub
 
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) HandlesButton1.Click 
        con.Open()
        Session("fname") = TextBox4.Text
        Session("lname") = TextBox5.Text

        str = "insert into employee values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & Sessio
("fname") & "','" & Session("lname") & "','" & TextBox6.Text & "','" & DropDownList1.SelectedValue &"')"
        com = New SqlCommand(str, con)
        com.ExecuteNonQuery()
        con.Close()
        Response.Redirect("sucess.aspx")
    End Sub
End Class

Success.aspx code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="sucess.aspx.vb" Inherits="sucess"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1
transitional.dtd">
 
<
html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<
body>
    <form id="form1" runat="server">
    <div>
    <asp:Label ID="Label1" runat="server" Height="61px" Text="Label" Width="200px"></asp:Label>
    </div>
    </form>
</body>
</
html>

Success.aspx.vb code

Partial Class sucess
    Inherits System.Web.UI.Page 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) HandlesMe.Load
        Label1.Text = "Welcome:" + "<h2>" + Session("fname") + Session("lname") + "</h2>"
    End Sub
End Class

Output

registrationform-in-VB-Net.gif

registrationform2.gif

registrationform3.gif 

COMMENT USING

Trending up