M.L. Martin
asked on
Button1_CLick error
Each time I execute the code on my local page I receive an error that Button1_Click is undefined. I can not see where I am doing so much with this code that it generates this error. Can someone point me in the right direction or simply tell me what I should add or change.
The button code on my UI page:
post1.aspx
The insert code (stored procedure) on my code behind page:
post1.aspx.vb
Note: The insert works correctly in the database but I still receive the error that Button1_Click is undefined.
The button code on my UI page:
post1.aspx
<%@ Page Title="" Language="VB" MasterPageFile="~/Site.Search.master" AutoEventWireup="false" CodeFile="post1.aspx.vb" Inherits="post1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<div>
<asp:TextBox ID="name" runat="server"></asp:TextBox>
</div>
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="Button1_Click" />
</div>
<div>
</div>
</asp:Content>
The insert code (stored procedure) on my code behind page:
post1.aspx.vb
Imports System.Data
Imports System.Data.SqlClient
Partial Class post1
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strConnString As String = ConfigurationManager.ConnectionStrings("SQL2008R2_504887_golivefitnesConnectionString").ConnectionString
Dim con As New SqlConnection(strConnString)
Dim cmd As New SqlCommand()
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "namesearchs"
cmd.Parameters.Add("@nameser", SqlDbType.VarChar).Value = name.Text.Trim()
'cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = txtLastName.Text.Trim()
'cmd.Parameters.Add("@BirthDate", SqlDbType.DateTime).Value = txtBirthDate.Text.Trim()
'cmd.Parameters.Add("@City", SqlDbType.VarChar).Value = txtCity.Text.Trim()
'cmd.Parameters.Add("@Country", SqlDbType.VarChar).Value = txtCountry.Text.Trim()
cmd.Connection = con
Try
con.Open()
cmd.ExecuteNonQuery()
'lblMessage.Text = "Record inserted successfully"
Catch ex As Exception
Throw ex
Finally
con.Close()
con.Dispose()
End Try
End Sub
End Class
Note: The insert works correctly in the database but I still receive the error that Button1_Click is undefined.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bug fixed.
ASKER