Results 1 to 4 of 4

Thread: Example of registration form

  1. #1

  2. #2
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    Re: Example of registration form

    Here you go:

    Just modify to use pagebehind and seperate business logic from UI:

    Code:
    <%@ Page Language="vb" Debug="true" %>
    <%@ import Namespace="System.Data" %>
    <%@ import Namespace="System.Data.SqlClient" %>
    <%@ import Namespace="System.Web.Mail" %>
    <script runat="server">
    
        Sub Page_Load(src as Object, e As EventArgs)
               If Not IsPostBack then
                   LoadClients()
               end if
           End Sub
        
           Sub LoadClients()
             Dim conMyData As SqlConnection
    	 Dim cmdSelect As SqlCommand
             Dim reader as SqlDataReader
           
    	'try and make a connection
           	Try
                  conMyData = New SqlConnection( ConfigurationSettings.AppSettings("strConn") )
                  cmdSelect = New SqlCommand( "select_clients", conMyData )
                  cmdSelect.CommandType = CommandType.StoredProcedure
                  conMyData.Open()
        
                  reader = cmdSelect.ExecuteReader()
        
                  ddlClient.DataSource = reader
                  ddlClient.DataTextField = "Client"
                  ddlClient.DataValueField= "ClientID"
                  ddlClient.DataBind()
               'catch any exceptions that might be thrown
        	Catch e as Exception
               Response.Write("An Error Occurred: " & e.toString())
           	'clean up and close resources
           	Finally
              reader.Close()
               conMyData.Close()
           	End Try
        
           End Sub
        
        Sub Button_Click(sender As Object, e As EventArgs)
            If Not IsValid Then
               lblMessage.Text = "You must fill in all the required fields before submitting the form!"
            else
    	  
              'try and validate the password 
    	  if (ValidatePassword(txtPassword.Text, txtConfirmPassword.Text)) then
    		'password validated
    		
    		'first do the insert
    		if InsertUser() then
    			'then do the email send
    			SendConfirmation()
    
    			'finally give the user a message
    	           	lblMessage.Text = "Thank You for registering as an IMS User." & vbCrlf & "Your username to enter the system is: " & LCase(Left(txtFirstName.Text,1) & txtLastName.Text) & "." & vbCrlf & "An e-mail message will be sent to you with login details."
    		        hlLogin.Text = "Go back to the IMS Login page."
    			hlLogin.NavigateURL = "login.aspx"
    		else
    			lblMessage.Text = "This user already is registered in the IMS system!"
    		end if
    	  else
    		'bad confirmation
    		lblMessage.Text = "Your password does not match the confirmation password!"
    		hlLogin.Text = ""
    	  end if
           end if
        End Sub
        
        Function InsertUser() as Boolean
    	 Dim conMyData As SqlConnection
    	 Dim cmdSelect As SqlCommand
             Dim reader as SqlDataReader
           	 Dim parmReturnValue as SqlParameter
    	 Dim intResult as Integer
    	 Dim bNew as Boolean
    
    	'try and make a connection
           	Try
                  conMyData = New SqlConnection( ConfigurationSettings.AppSettings("strConn") )
                  cmdSelect = New SqlCommand( "insert_register_user", conMyData )
                  cmdSelect.CommandType = CommandType.StoredProcedure
                  parmReturnValue = cmdSelect.Parameters.Add("RETURN_VALUE", SqlDbType.Int)
    	      parmReturnValue.Direction = ParameterDirection.ReturnValue
    	      
    	      cmdSelect.Parameters.Add("@FirstName", txtFirstName.Text)
    	      cmdSelect.Parameters.Add("@LastName", txtLastName.Text)
    	      cmdSelect.Parameters.Add("@ClientID", ddlClient.SelectedItem.Value)
    	      cmdSelect.Parameters.Add("@EmailAddress", txtEmail.Text)
    	      cmdSelect.Parameters.Add("@Password", txtPassword.Text)
    	      cmdSelect.Parameters.Add("@Title", txtTitle.Text)
    	      cmdSelect.Parameters.Add("@Telephone", txtTelephone.Text)
    	      	
    	      conMyData.Open()
        	      cmdSelect.ExecuteNonQuery()	
    	      intResult = cmdSelect.Parameters("RETURN_VALUE").Value	
    	
    		if intResult = -1 then
    			bNew = False
    		else
    			'do nothing
    			bNew = True
    		end if
        	Catch e as Exception
               Response.Write("An Error Occurred: " & e.toString())
           	'clean up and close resources
           	Finally
               conMyData.Close()
           	End Try
    	InsertUser = bNew
        End Function
        
        Sub SendConfirmation
    	Dim objMailMessage As MailMessage
            Dim strHTMLBody as String
    
                objMailMessage = New MailMessage
        
               'from and to
                objMailMessage.From = "[email protected]"
                objMailMessage.To = txtEmail.Text
        
               'mail details
                objMailMessage.Subject = "IMS New User Registration Info"
                strHTMLBody = "<html><head><title>Login Information</title></head>" & _
    		     "<body><font face=Arial, Helvetica, sans-serif size=2>" & _
    		     "<HR><H2><font color=red><b>Login Information</b></font></H2><HR><br>Hello <b>" & txtFirstName.Text & " " & txtLastName.Text & "</b>," & "<br><br>" & _
    	             "You have completed the <font color=blue><b>IMS</b></font> registration process.  The following information will help you log into the system:<br>" & _ 
    		     "<UL><LI>User Name:<b>" & LCase(Left(txtFirstName.Text, 1) & txtLastName.Text) & "</b></li><LI>Password: <font color=green><b>" & txtPassword.Text & "</b></font>" & "</LI></UL>" & _
    		     "This is an automatic e-mail notification from the <font color=blue><b>IMS</b></font> system, please do <U><B><font color=red>NOT</font></B></U> reply to this e-mail address!" & "<br><br>" & "Thank You</font></body></html>"
    	   objMailMessage.Body = strHTMLBody
    	   objMailMessage.BodyFormat = MailFormat.HTML
    	   SmtpMail.Send(objMailMessage)
        End Sub
    
    
        Function ValidatePassword(txtP as String, txtCP as String) As Boolean
    	If (txtP = txtCP)
    		ValidatePassword = True
    	else
    		ValidatePassword = False
    	end if
        End Function
    
    </script>
    That is the vb code

  3. #3
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Attached
    Attached Files Attached Files

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width