Hi
I really am in need of help due to being a beginner to this.
I have the following code: -
<%@ Page Language="
VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<script runat="server">
Sub Page_Load
If Not Request.Cookies("EmailRegister") is nothing Then
txtEmailAddress.Visible = False
lblRegister.Text = "You have registered for email updates"
btnRegister.visible = False
End If
End Sub
Function AddNewCustomerEmail(ByVal CustomerEmail As String) As Integer
Dim connectionString As String = _
ConfigurationSettings.AppSettings("ConnectionStrin g")
Dim dbConnection As System.Data.IDbConnection = _
New System.Data.OleDb.OleDbConnection(connectionString )
Dim queryString As String = "INSERT INTO [Customers] ([EmailAddress]) VALUES (@customerEmail)"
Dim dbCommand As System.Data.IDbCommand = _
New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim rowsAffected As Integer = 0
dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Finally
dbConnection.Close
End Try
Return rowsAffected
End Function
Function CheckCustomerEmailAddresses(ByVal emailAddress As String) As Boolean
Dim connectionString As String = _
ConfigurationSettings.AppSettings("ConnectionStrin g")
Dim dbConnection As System.Data.IDbConnection = _
New System.Data.OleDb.OleDbConnection(connectionString )
Dim queryString As String = "SELECT COUNT ([Customers].[EmailAddress])" & _
"FROM [Customers] WHERE ([Customers].[EmailAddress] = @EmailAddress)"
Dim dbCommand As System.Data.IDbCommand = _
New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_emailAddress As System.Data.IDataParameter = _
New System.Data.OleDb.OleDbParameter
dbParam_emailAddress.ParameterName = "@EmailAddress"
dbParam_emailAddress.Value = emailAddress
dbParam_emailAddress.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_emailAddress)
Dim Result As Integer = 0
dbConnection.Open
Try
Result = dbCommand.ExecuteScalar
Finally
dbConnection.Close
End Try
If Result > 0 Then
Return true
Else Return False
End If
End Function
Sub btnRegister_Click(sender As Object, e As EventArgs)
Dim CustomerEmail as String = txtEmailAddress.Text
'Check whether the email address is already registered.
'If not, we need to register it by calling the AddNewCustomerEmail() method
If CheckCustomerEmailAddresses(CustomerEmail) = false Then
AddNewCustomerEmail(CustomerEmail)
End If
'Email has been registered, so update the display and attempt to set a cookie.
txtEmailAddress.Visible = False
lblRegister.Text = "You have registered for email updates."
btnRegister.visible = false
Dim EmailRegisterCookie as New HttpCookie("EmailRegister")
EmailRegisterCookie.Value = CustomerEmail
EmailRegisterCookie.Expires = now.AddSeconds(20)
Response.Cookies.Add(EmailRegisterCookie)
End Sub
</script>
<html>
<head>
<body>
<form runat="server">
<fieldset width="250">
<p>
</p>
<legend>Newsletter Registration</legend><asp:Label id="lblRegister" runat="server" text="Register for email updates"></asp:Label>
<asp:TextBox id="txtEmailAddress" runat="server"></asp:TextBox>
<asp:Button id="btnRegister" onclick="btnRegister_Click" runat="server" Width="60" Text="Register"></asp:Button>
<p>
<asp:RegularExpressionValidator id="validEmail" runat="server" ErrorMessage="Please enter a valid email address." ControlToValidate="txtEmailAddress" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</p>
</fieldset>
</form>
</body>
</html>
When I click the register it won't produce the message of the email being registered?
Please can someone tell me what I am doing wrong?
Thanks