Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2006, 03:59 PM
Authorized User
 
Join Date: Sep 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Email Registering

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
 
Old September 20th, 2006, 04:21 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I dont understand, the message: "You have registered for email updates." doesnt display?

--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Registering users Glaman BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 March 5th, 2008 07:39 PM
Registering ASCX gbrown ASP.NET 1.0 and 1.1 Professional 1 January 9th, 2007 11:57 AM
Registering a new user hasanali00 BOOK: ASP.NET Website Programming Problem-Design-Solution 4 April 14th, 2005 05:07 AM
Registering DLL's askenkray Classic ASP Components 4 January 27th, 2005 03:05 PM
Registering a new user ssaylanc BOOK: ASP.NET Website Programming Problem-Design-Solution 4 January 9th, 2005 04:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.