Professional Documents
Culture Documents
This Tutorial Will Demonstrate How To Create A Registration Page For New Users To Your Site
This Tutorial Will Demonstrate How To Create A Registration Page For New Users To Your Site
This
registration page will utilize the same principles used in the Login Page Tutorial, so this should be no
more difficult to do than the login page. I am using the SQL Server 2000, and programmed this part
of the application in Visual Studio .NET 2003. I choose VB because it is more natural language to
me, but there is no reason you can't use the same concepts I use here to code this in any other
language in the .NET framework.
1. Create the basic HTML layout for the registration page. REGISTER.ASPX
- This page will require all entries to be filled in for a successful registration
- UserName, Password, FirstName and LastName
(Toggle Plain Text)
2. Create the Store Procedures you will need to add a new user
- You will need to handle duplicates
- You will need to handle the adding of a new user.
End Sub
Try
' ||||| Check if Connection to DB is already open, if not,
then open a connection
If MyConn.State = ConnectionState.Closed Then
' ||||| DB not already Open...so open it
MyConn.Open()
MyCmd.ExecuteNonQuery()
End If
' ||||| Was the return value greater than 0 ???
If objReturnParam.Value > 0 Then
lblResult.Text = "UserName already exists or you are
already a registered user!"
Return False
Else
Return True
End If
Catch ex As Exception
lblError.Text = "Error Connecting to Database!"
End Try
End Function
Try
' ||||| Check if Connection to DB is already open, if not,
then open a connection
' ||||| DB not already Open...so open it
MyConn.Open()
MyCmd.ExecuteNonQuery()
Catch ex As Exception
lblError.Text = "Error Connecting to Database!"
End Try
End Sub
End Class
5. Final thing to do: Link the Registration Page to the Login Page
- I used a Hyperlink on the login page to do this, but you could use anything. It is just a simple <a
href="Register.aspx" ...> line of code to use for this. On that note I also send the user right back to
the login page on successful registration. This is not the ideal thing to do. It would be better to direct
them to a page that said "You are now registered! Would you like to return to the login page?" and a
means of allowing them to return to the login page. But you specific use of this may be different, so
the choice is yours.
Happy coding
Paladine
Master Poster
Offline
793 posts
since Feb 2003
Ads by Google
Permalink
0
Re: ASP.NET Registration Page
Nice this is good stuff Paladine.
Miller
millers_35
Newbie Poster
Offline
18 posts
since Apr 2005
Permalink
0
Re: ASP.NET Registration Page
Hi
I have tried to add more fields ie: Address, Phone, Email etc everything compiles ok but when
running the app it comes up with the database error (lblError)
I have updated the Stored procedure and the database with the correct fields so i think i know it is
not that.
End Sub
Protected WithEvents txtUserName As System.Web.UI.WebControls.TextBox
Protected WithEvents rvUserName As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents txtPassword As System.Web.UI.WebControls.TextBox
Protected WithEvents rvPassword As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents txtFirst As System.Web.UI.WebControls.TextBox
Protected WithEvents rvFirstName As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents txtLast As System.Web.UI.WebControls.TextBox
Protected WithEvents rvLastName As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents cmdSubmit As System.Web.UI.WebControls.Button
Protected WithEvents lblError As System.Web.UI.WebControls.Label
Protected WithEvents lblResult As System.Web.UI.WebControls.Label
Protected WithEvents txtCompany As System.Web.UI.WebControls.TextBox
Protected WithEvents rvCompany As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents txtAddress As System.Web.UI.WebControls.TextBox
Protected WithEvents rvAddress As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents txtCity As System.Web.UI.WebControls.TextBox
Protected WithEvents rvCity As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents txtPostCode As System.Web.UI.WebControls.TextBox
Protected WithEvents rvPostCode As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents txtEmail As System.Web.UI.WebControls.TextBox
Protected WithEvents rvEmail As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents txtPhone As System.Web.UI.WebControls.TextBox
Protected WithEvents rvPhone As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents txtFax As System.Web.UI.WebControls.TextBox
#End Region
Try
' |||| Check if Connection to the DB is already open , if not,
then open a connection
If MyConn.State = ConnectionState.Closed Then
' |||| DB not already open... so open it
MyConn.Open()
MyCmd.ExecuteNonQuery()
End If
' |||| Was the return value greater that 0?
If objReturnParam.Value > 0 Then
lblResult.Text = "UserName already exists or you are
already a registered user!"
Return False
Else
Return True
End If
' |||| Close the connection Closes with it
MyConn.Close()
Catch ex As Exception
lblError.Text = "Error Connecting to DataBase!"
End Try
End Function
Try
' |||| Check if connection is already open
MyConn.Open()
MyCmd.ExecuteNonQuery()
MyConn.Close()
Catch ex As Exception
lblError.Text = "Error Connecting to DataBase!"
End Try
End Sub
End Class