Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BC30506: Handles clause requires a WithEvents variable.

Status
Not open for further replies.

markdmac

MIS
Dec 20, 2003
12,340
US
I hope someone can assist me here. I've been searching online about the error I am getting but the solutions I am finding all refer to a code behind page which I do not have.

The error I am getting is:
Code:
BC30506: Handles clause requires a WithEvents variable.
Line 15: 	Public Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("\fpdb\guestbook.mdb") & ";"
Line 16: 	
[red]Line 17: 	Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
[/red]Line 18: 		Dim cmd As New OleDbCommand("INSERT INTO [guestlog] ([Firstname], [Lastname], [Email],[Lot],[IP]) VALUES ('" &txtFirstName.Text & "','" & txtLastName.Text & "','" & txtEmail.Text & "','" & txtLot.Text & ClientIP &"')", New OleDbConnection(strConn))
Line 19: 		cmd.Connection.Open()

My page simply grabs data from a form and is supposed to add it to an Access database. Here is the code I have, I hope someone can suggest a fix. Thanks in advance.

Code:
<%@ Page Language="VB" %>
<%@ import Namespace="System.Drawing" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<%@ import Namespace="System.Web.UI.Page" %>
<%
Dim ClientIP, btype
%>
<% ClientIP=Request.ServerVariables("REMOTE_HOST")%>
<% btype=Request.ServerVariables("HTTP_USER_AGENT") %> 
<%
%>
<script runat="server">

	Public Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("\fpdb\guestbook.mdb") & ";"
	
	Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
		Dim cmd As New OleDbCommand("INSERT INTO [guestlog] ([Firstname], [Lastname], [Email],[Lot],[IP]) VALUES ('" &txtFirstName.Text & "','" & txtLastName.Text & "','" & txtEmail.Text & "','" & txtLot.Text & ClientIP &"')", New OleDbConnection(strConn))
		cmd.Connection.Open()
		cmd.ExecuteNonQuery()
		cmd.Connection.Close()
		LoadData()
	End Sub
</script>

	

<html>   
<body<%
If instr(btype,"MSIE") = 0 Then
Response.Write " bgcolor='#559BDA'"
End If
%>>
<div align="center">

	<form id="Form1" method="post" runat="server">
	<p align="center">Spammers Beware!&nbsp; Your IP Address is being recorded.&nbsp; 
	Attempts to spam our Guest Book will be reported to your ISP.<br>
	Your IP Address is: {<% Response.Write(ClientIP) %>}</p>
	<p>
	<br>
	</p>
	<table bordercolor=#559BDA border=1 bgcolor="Gray">
    <tr>
		<td><strong>Sign the Guest Book</strong></td>
	</tr>
    <tr bgcolor="goldenrod">
        <td bgcolor="#99CCFF"><b>First Name</b></td>
        <td bgcolor="#99CCFF"><b>Last Name</b></td>
        <td bgcolor="#99CCFF"><b>E-Mail</b></td>
        <td colspan="2" bgcolor="#99CCFF"><b>Lot Number</b></td>
    </tr>    
    <tr>
    <td><asp:TextBox id="txtFirstName" runat="server" Width="77px"></asp:TextBox></td>
    <td><asp:TextBox id="txtLastName" runat="server" Width="77px"></asp:TextBox></td>
    <td><asp:TextBox id="txtEmail" runat="server"></asp:TextBox></td>
    <td><asp:TextBox id="txtLot" runat="server" Width="345px"></asp:TextBox></td>
    <td><asp:button id="btnInsert" onclick="btnInsert_Click" runat="server" text="Sign Guestbook"></asp:button></td>
    </tr>
    <tr>
    <td colspan="4">
	</td>
	</tr>
    </table>
	</form>

	<p>&nbsp;</p>
	<p>Privacy Notice: Any information you enter on our Web site or give us in 
	any other way will be held in strict confidence. You may choose not to 
	provide certain information. We use the information that you provide for 
	such purposes as responding to your requests, customizing future content, 
	improving our site, and communicating with you.&nbsp; Under no circumstances 
	will the Higley Groves Homeowners Association or its' contracted management 
	company sell, rent or share your information with any outside party without 
	your written consent.</p>
	&nbsp;</td>
</div>
</body>
</html>

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Handles" signatures are used by code-behind pages (which is why all the articles you have seen refer to them). I believe that if you don't use a code behind page, you don't need the Handles signature.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Is there any reason why you are not using the code behind approach? There are many advantages to using that method and will make life easier for you.

I'll be happy to knock up an example of how the above page could be done using ASP.NET preferred approach, rather than the classic asp methods that you've used above, if that will help?


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
OK, here's an example anyway using the code behind model and I've addressed a few other issues that I think can be improved on based on the initial example:

1) CSS should be used for the page layout
2) Classic asp coding (i.e. inline logic between <% %> blocks) should be removed and moved to the code-behind page
3) The framework should be used for methods such as retrieving the IP address and user agent
4) Parameters should be used when writing to the database to protect against SQL Injection attacks

Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default1.aspx.vb" Inherits="Default1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .block {display:block;}
        .guestItem {float:left;margin-right:10px;}
        .guestbookbutton {margin-top:20px;}
        .bodyIE {background-color:#559BDA;}
    </style>
</head>
<body runat="server" id="body">
    <form id="form1" runat="server">

    <div>
        <p align="center">Spammers Beware!&nbsp; Your IP Address is being recorded.&nbsp;
            Attempts to spam our Guest Book will be reported to your ISP.<br>
            Your IP Address is: {<asp:Label ID="lblIPAddress" runat="server"></asp:Label>}</p>
        <fieldset>
            <legend>Sign The Guestbook</legend>
            <div class="guestItem">
                <asp:Label ID="lblFirstName" runat="server" AssociatedControlID="txtFirstName" Text="First Name" CssClass="block"></asp:Label>
                <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
            </div>
            <div class="guestItem">
                <asp:Label ID="lblLastName" runat="server" AssociatedControlID="txtLastName" Text="Last Name" CssClass="block"></asp:Label>
                <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
            </div>
            <div class="guestItem">
                <asp:Label ID="lblEmail" runat="server" AssociatedControlID="txtEmail" Text="Email" CssClass="block"></asp:Label>
                <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
            </div>
            <div class="guestItem">
                <asp:Label ID="lblLotNumber" runat="server" AssociatedControlID="txtLotNumber" Text="Lot Number" CssClass="block"></asp:Label>
                <asp:TextBox ID="txtLotNumber" runat="server"></asp:TextBox>
            </div>
            <div class="guestItem">
                <asp:Button ID="btnInsert" runat="server" Text="Sign Guestbook" CssClass="guestbookbutton" />
            </div>                                                
        </fieldset>    
        
        <asp:Label ID="lblConfirmation" runat="server" Text="Thank you for your entry" Visible="false"></asp:Label>
        
        <p>Privacy Notice: Any information you enter on our Web site or give us in
        any other way will be held in strict confidence. You may choose not to
        provide certain information. We use the information that you provide for
        such purposes as responding to your requests, customizing future content,
        improving our site, and communicating with you.&nbsp; Under no circumstances
        will the Higley Groves Homeowners Association or its' contracted management
        company sell, rent or share your information with any outside party without
        your written consent.</p>
    </div>

    </form>
</body>
</html>
Code:
Imports System.Data.OleDb
Partial Class Default1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            ' Show the user's IP Address
            lblIPAddress.Text = Request.UserHostAddress
            ' Set the background color based on the user agent
            If Request.UserAgent.Contains("MSIE") Then
                body.Attributes.Add("class", "bodyIE")
            End If
        End If
    End Sub

    Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click
        ' Define the query with parameters
        Dim strQuery As String = "INSERT INTO [guestlog] ([Firstname], [Lastname], [Email],[LotNumber],[IPAddress]) VALUES (@FirstName,@LastName,@Email,@LotNumber,@IPAddress)"

        ' Create the command and connection (the connection string comes from the web.config file)
        Dim cmd As New OleDbCommand(strQuery, New OleDbConnection(ConfigurationManager.ConnectionStrings("mydatabase").ConnectionString))

        ' Add the parameter values
        cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text.Trim)
        cmd.Parameters.AddWithValue("@LastName", txtLastName.Text.Trim)
        cmd.Parameters.AddWithValue("@Email", txtEmail.Text.Trim)
        cmd.Parameters.AddWithValue("@LotNumber", txtLotNumber.Text.Trim)
        cmd.Parameters.AddWithValue("@IPAddress", Request.UserHostAddress)

        ' Open the connection and execute the command
        cmd.Connection.Open()
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()

        ' Show a confirmation
        lblConfirmation.Visible = True

        ' call your other function
        LoadData()
    End Sub

    Private Sub LoadData()
        ' Your logic here
    End Sub

End Class


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Thanks ca8msm!

As you have probably surmised I am new to ASP.Net. I don't have an aversion to using the code behind page, only I did not have an example and as was deduced I am not using Visual Studio.

I have tried the above code but am getting the following error message:
Parser Error Message: Could not load type 'Default1'.
Source Error:
Line 1: <%@ Page Language="VB" AutoEventWireup="false" CodeFile="signguestbook.aspx.vb" Inherits="Default1" %>

I made sure that the CodeFile name matches where I saved the code behind page and I made no changes to the suggested code behind page.

Any help would be greatly appreciated.

 
Try:

Inherits="Default" or Inherits="signguestbook_Default
 
I installed Visual Web Developer Express, opened the pages and saved them. Does not appear to have made any changes. My error is the same. I tried the variations in Tipmaster's post but no joy. returned the code to what was posted by ca8msm. Anybody have any more suggestions?
 
create a new page and use the code behind model and then see what errors you get and then post back,
 
i clearly don't understand the proper steps to do this. I created a new page using Visual Web Developer. Added a form, table and ASP text boxes and submit button. I did not automatically get a code behind page.

After trying to rebuild this, here is the page I get and the error I am getting.

Code:
Compiler Error Message: BC30002: Type 'OleDbCommand' is not defined.

Source Error:

Line 9:  
Line 10:         ' Create the command and connection (the connection string comes from the web.config file)
[red]Line 11:         Dim cmd As New OleDbCommand(strQuery, New OleDbConnection(ConfigurationManager.ConnectionStrings("mydatabase").ConnectionString))
[/red]Line 12: 
Line 13:         ' Add the parameter values

Code:
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<script runat="server">

    Protected Sub btnGuestBook_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Define the query with parameters
        Dim strQuery As String = "INSERT INTO [guestlog] ([Firstname], [Lastname], [Email],[LotNumber],[IPAddress]) VALUES (@FirstName,@LastName,@Email,@LotNumber,@IPAddress)"

        ' Create the command and connection (the connection string comes from the web.config file)
        Dim cmd As New OleDbCommand(strQuery, New OleDbConnection(ConfigurationManager.ConnectionStrings("mydatabase").ConnectionString))

        ' Add the parameter values
        cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text.Trim)
        cmd.Parameters.AddWithValue("@LastName", txtLastName.Text.Trim)
        cmd.Parameters.AddWithValue("@Email", txtEmail.Text.Trim)
        cmd.Parameters.AddWithValue("@LotNumber", txtLot.Text.Trim)
        cmd.Parameters.AddWithValue("@IPAddress", Request.UserHostAddress)

        ' Open the connection and execute the command
        cmd.Connection.Open()
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()

        ' Show a confirmation
        lblConfirmation.Visible = True

        ' call your other function
        LoadData()
    End Sub
    
    Private Sub LoadData()
        ' Your logic here
    End Sub
</script>

<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
    <style type="text/css">
        .block {display:block;}
        .guestItem {float:left;margin-right:10px;}
        .guestbookbutton {margin-top:20px;}
        .bodyIE {background-color:#559BDA;}
    </style>
    <title>Guest Book</title>
</head>
<body style="text-align: center">
    <form id="form1" runat="server">
    <div>
        &nbsp;<div style="text-align: center">
            <p align="center">
                    Spammers Beware!&nbsp; Your IP Address is being recorded.&nbsp;
                    <br />
                    Attempts to spam our Guest Book will be reported to your ISP.<br />
                    Your IP Address is: {<asp:Label ID="lblIPAddress" runat="server"></asp:Label>}</p>
                <br />
            <table border="1" bgcolor="#33ccff">
                <tr>
                    <td style="width: 100px; text-align: center;">
                        First Name</td>
                    <td style="width: 100px; text-align: center;">
                        Last Name</td>
                    <td style="width: 100px; text-align: center;">
                        Email</td>
                    <td style="width: 100px; text-align: center;">
                        Lot #</td>
                </tr>
                <tr>
                    <td style="width: 100px">
                        <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox></td>
                    <td style="width: 100px">
                        <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox></td>
                    <td style="width: 100px">
                        <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox></td>
                    <td style="width: 100px">
                        <asp:TextBox ID="txtLot" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td colspan="4">
                        <asp:Button ID="btnGuestBook" runat="server" OnClick="btnGuestBook_Click" Text="Sign Guest Book" /></td>
                </tr>
            </table>
            </div>
        </div>
        <br />
        <asp:Label ID="lblConfirmation" runat="server" Text="Label" Width="604px"></asp:Label><br />
    
    
    </form>
</body>
</html>

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Yes, there is something fundamentally wrong with the page you have created as it isn't pointing to the code behind file. In the versionof Visual Studio I have, when you create a new page, there is a checkbox option to "Place code in seperate file". This will then create both the aspx and aspx.vb pages. The aspx page will have a CodeFile property in it's Page directive (at the top of the page) that points it to it's code file.

If this is not happening for you, I suggest you explore the different options available when adding a new page as I imagine it will be something similar. Once you've got this bit sorted and have two files, just add the relevant bits from my example above.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Oh, and the error you were getting is because you didn't have an Imports statement that pointed to the System.Data.Oledb namespace.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
OK, Visual Web Developer Express does have that same checkbox. I checked it and after double clicking the Submit button the code behind page was created.

I recreated my form, gave all the fileds the same names as before and pasted the code behind code from ca8msm. I get an error in loading the class identified in the Inherits line.

Code:
Parser Error Message: Could not load type 'Default1'.

Source Error: 

Line 1:  <%@ Page Language="VB" AutoEventWireup="false" CodeFile="gb.aspx.vb" Inherits="Default1" %>
Line 2:  
Line 3:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

Here is my code behind page
Code:
Imports System.Data.OleDb
Partial Class Default1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            ' Show the user's IP Address
            lblIPAddress.Text = Request.UserHostAddress
            ' Set the background color based on the user agent
            If Request.UserAgent.Contains("MSIE") Then
                body.Attributes.Add("class", "bodyIE")
            End If
        End If
    End Sub

    Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click
        ' Define the query with parameters
        Dim strQuery As String = "INSERT INTO [guestlog] ([Firstname], [Lastname], [Email],[LotNumber],[IPAddress]) VALUES (@FirstName,@LastName,@Email,@LotNumber,@IPAddress)"

        ' Create the command and connection (the connection string comes from the web.config file)
        Dim cmd As New OleDbCommand(strQuery, New OleDbConnection(ConfigurationManager.ConnectionStrings("mydatabase").ConnectionString))

        ' Add the parameter values
        cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text.Trim)
        cmd.Parameters.AddWithValue("@LastName", txtLastName.Text.Trim)
        cmd.Parameters.AddWithValue("@Email", txtEmail.Text.Trim)
        cmd.Parameters.AddWithValue("@LotNumber", txtLot.Text.Trim)
        cmd.Parameters.AddWithValue("@IPAddress", Request.UserHostAddress)

        ' Open the connection and execute the command
        cmd.Connection.Open()
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()

        ' Show a confirmation
        lblConfirmation.Visible = True

        ' call your other function
        LoadData()
    End Sub

    Private Sub LoadData()
        ' Your logic here
    End Sub

End Class

And here is the main page
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="gb.aspx.vb" Inherits="Default1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
    <style type="text/css">
        .block {display:block;}
        .guestItem {float:left;margin-right:10px;}
        .guestbookbutton {margin-top:20px;}
        .bodyIE {background-color:#559BDA;}
    </style>

    <title>Guest Book</title>
</head>
<body style="text-align: center">
    <form id="form1" runat="server">
    <div style="text-align: center">
        Spammers Beware!<br />
        Your IP address {<asp:Label ID="lblIPAddress" runat="server"></asp:Label>} is being recorded.<br />
        Any attempts to spam our database will be reported to your ISP.<br />
        <br />
        <table border="1">
            <tr>
                <td align="center" style="width: 100px; background-color: #33ccff">
                    First Name</td>
                <td align="center" style="width: 100px; background-color: #33ccff">
                    Last Name</td>
                <td align="center" style="width: 100px; background-color: #33ccff">
                    Email</td>
                <td align="center" style="width: 100px; background-color: #33ccff">
                    Lot #</td>
            </tr>
            <tr>
                <td align="center" style="width: 100px; background-color: #33ccff">
                    <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox></td>
                <td align="center" style="width: 100px; background-color: #33ccff">
                    <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox></td>
                <td align="center" style="width: 100px; background-color: #33ccff">
                    <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox></td>
                <td align="center" style="width: 100px; background-color: #33ccff">
                    <asp:TextBox ID="txtLot" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td align="center" colspan="4" style="background-color: #33ccff">
                    <asp:Button ID="btnSign" runat="server" Text="Sign Guest Book" /></td>
            </tr>
        </table>
    
    </div>
        <br />
        <asp:Label ID="lblConfirmation" runat="server" Width="653px"></asp:Label>
    </form>
</body>
</html>

As always, any help and suggestions are greatly appreciated.
 
OK, the problem is that you are pasting the full code I provided into a page that isn't called default1 and therefore the name of the class and the namespace is incorrect.

Either create a page named Default1 and overwrite all of the code with what I posted, or only replace the relevant sections.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Aha,

OK, so where I am seeing
inherits="Default1"

It was my understanding that this referred to the Partial Class in the code behind page. Are you saying that this name has to match the name of the CodeFile="gb.aspx.vb"?

Thanks for your patience in getting me there...just trying ot figure out what I need to edit now. Do I rename the code behind page or change the inherits= part? (or either).
 
The easiest way to solve this is for you to create a completely new page. Then, only paste this into the code behind file:
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            ' Show the user's IP Address
            lblIPAddress.Text = Request.UserHostAddress
            ' Set the background color based on the user agent
            If Request.UserAgent.Contains("MSIE") Then
                body.Attributes.Add("class", "bodyIE")
            End If
        End If
    End Sub

    Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click
        ' Define the query with parameters
        Dim strQuery As String = "INSERT INTO [guestlog] ([Firstname], [Lastname], [Email],[LotNumber],[IPAddress]) VALUES (@FirstName,@LastName,@Email,@LotNumber,@IPAddress)"

        ' Create the command and connection (the connection string comes from the web.config file)
        Dim cmd As New OleDbCommand(strQuery, New OleDbConnection(ConfigurationManager.ConnectionStrings("mydatabase").ConnectionString))

        ' Add the parameter values
        cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text.Trim)
        cmd.Parameters.AddWithValue("@LastName", txtLastName.Text.Trim)
        cmd.Parameters.AddWithValue("@Email", txtEmail.Text.Trim)
        cmd.Parameters.AddWithValue("@LotNumber", txtLotNumber.Text.Trim)
        cmd.Parameters.AddWithValue("@IPAddress", Request.UserHostAddress)

        ' Open the connection and execute the command
        cmd.Connection.Open()
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()

        ' Show a confirmation
        lblConfirmation.Visible = True

        ' call your other function
        LoadData()
    End Sub

    Private Sub LoadData()
        ' Your logic here
    End Sub
and this between the <html></html> tags of your page:
Code:
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .block {display:block;}
        .guestItem {float:left;margin-right:10px;}
        .guestbookbutton {margin-top:20px;}
        .bodyIE {background-color:#559BDA;}
    </style>
</head>
<body runat="server" id="body">
    <form id="form1" runat="server">

    <div>
        <p align="center">Spammers Beware!&nbsp; Your IP Address is being recorded.&nbsp;
            Attempts to spam our Guest Book will be reported to your ISP.<br>
            Your IP Address is: {<asp:Label ID="lblIPAddress" runat="server"></asp:Label>}</p>
        <fieldset>
            <legend>Sign The Guestbook</legend>
            <div class="guestItem">
                <asp:Label ID="lblFirstName" runat="server" AssociatedControlID="txtFirstName" Text="First Name" CssClass="block"></asp:Label>
                <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
            </div>
            <div class="guestItem">
                <asp:Label ID="lblLastName" runat="server" AssociatedControlID="txtLastName" Text="Last Name" CssClass="block"></asp:Label>
                <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
            </div>
            <div class="guestItem">
                <asp:Label ID="lblEmail" runat="server" AssociatedControlID="txtEmail" Text="Email" CssClass="block"></asp:Label>
                <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
            </div>
            <div class="guestItem">
                <asp:Label ID="lblLotNumber" runat="server" AssociatedControlID="txtLotNumber" Text="Lot Number" CssClass="block"></asp:Label>
                <asp:TextBox ID="txtLotNumber" runat="server"></asp:TextBox>
            </div>
            <div class="guestItem">
                <asp:Button ID="btnInsert" runat="server" Text="Sign Guestbook" CssClass="guestbookbutton" />
            </div>                                                
        </fieldset>    
        
        <asp:Label ID="lblConfirmation" runat="server" Text="Thank you for your entry" Visible="false"></asp:Label>
        
        <p>Privacy Notice: Any information you enter on our Web site or give us in
        any other way will be held in strict confidence. You may choose not to
        provide certain information. We use the information that you provide for
        such purposes as responding to your requests, customizing future content,
        improving our site, and communicating with you.&nbsp; Under no circumstances
        will the Higley Groves Homeowners Association or its' contracted management
        company sell, rent or share your information with any outside party without
        your written consent.</p>
    </div>

    </form>
</body>
Don't make any other changes and it will work.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Still the same error.

Parser Error Message: Could not load type 'gb'.

Source Error:


Line 1: <%@ Page Language="VB" AutoEventWireup="false" CodeFile="gb.aspx.vb" Inherits="gb" %>


The only deviation I made to your instructions was to add the line Imports System.Data.OleDbPartial

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top