This is my code for Register.aspx.
How can I make this postback at a specific point in the code???????without using Response.Redirect("Register.aspx") -- which is posting back to itself.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblDupEmail.Text = "This Email Address already exists. <br> Please enter another or <a href='login.aspx' class='Orange'>go to Sign In page.</a>"
lblError.Text = "An unexpected error occurred. Please try again."
If IsPostBack Then
If Not Session("Duplicate") Is Nothing Then
lblDupEmail.Visible = True
End If
If Not Session("Error") Is Nothing Then
lblError.Visible = True
End If
End If
End Sub
Public Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegister.Click
If IsValid Then
Dim myCONN As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))
Dim sSql As String = "SELECT Email FROM Member WHERE Email = @Email"
Dim selectCmd As New SqlCommand(sSql, myCONN)
selectCmd.CommandType = CommandType.Text
selectCmd.Connection = myCONN
selectCmd.Parameters.Add("@Email", SqlDbType.NVarChar, 100)
selectCmd.Parameters("@Email").Value = txtEmail.Text
Dim bDuplicate As Boolean
bDuplicate = False
Dim da As SqlDataReader
Try
myCONN.Open()
da = selectCmd.ExecuteReader(CommandBehavior.SingleRow)
da.Read()
sEmail = da.Item("Email")
myCONN.Close()
bDuplicate = True
'This Response.Redirect doesn't work
'When I put Response.Write("Duplicate Email") it works
Response.Redirect("Register.aspx")
Catch ex As Exception
Me.Insert()
Finally
If myCONN.State = ConnectionState.Open Then
myCONN.Close()
End If
End Try
End If
End Sub
Private Sub Insert()
Dim myCONN As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))
Dim sSql As String = "INSERT INTO OCVBUG_Member (FName, LName, Email, Password ) VALUES(@FName, @LName, @Email, @Password)"
Dim insertCmd As New SqlCommand(sSql, myCONN)
insertCmd.CommandType = CommandType.Text
insertCmd.Connection = myCONN
insertCmd.Parameters.Add("@FName", SqlDbType.NVarChar, 50)
insertCmd.Parameters.Add("@LName", SqlDbType.NVarChar, 50)
insertCmd.Parameters.Add("@Email", SqlDbType.NVarChar, 50)
insertCmd.Parameters.Add("@Password", SqlDbType.NVarChar, 100)
insertCmd.Parameters("@FName").Value = Replace(txtFName.Text, "'", "''")
insertCmd.Parameters("@LName").Value = Replace(txtLName.Text, "'", "''")
insertCmd.Parameters("@Email").Value = Replace(txtEmail.Text, "'", "''")
Dim sPassword = txtPassword.Text
sPassword = sPassword
insertCmd.Parameters("@Password").Value = FormsAuthentication.HashPasswordForStoringInConfig File(sPassword, "SHA1")
bSuccess = True
Try
myCONN.Open()
insertCmd.ExecuteScalar()
myCONN.Close()
Catch ex As Exception
bSuccess = False
Session("Error") = bSuccess.ToString
Response.Redirect("Register.aspx")
Response.End()
Finally
If myCONN.State = ConnectionState.Open Then
myCONN.Close()
End If
End Try
If bSuccess = True Then
Response.Redirect("Regconfirm.aspx")
End If
End Sub
End Class
|