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:

<%@ Page Title="" Language="VB" MasterPageFile="~/Site.Search.master" AutoEventWireup="false" CodeFile="post1.aspx.vb" Inherits="post1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
    <asp:TextBox ID="name" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="Button1_Click" />

Open in new window

The insert code (stored procedure) on my code behind page:

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
            'lblMessage.Text = "Record inserted successfully"
        Catch ex As Exception
            Throw ex
        End Try

    End Sub

End Class

Open in new window

Note: The insert works correctly in the database but I still receive the error that Button1_Click is undefined.
derrekdeveloperEnterprise Solution ArchitectAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lokesh B RDeveloperCommented:

OnClientClick is a Client Side function.
OnClick is a Server Side function.

So you need to change as below.

<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
derrekdeveloperEnterprise Solution ArchitectAuthor Commented:
Thanks Lokesh. Just changed it and the bug went away.
derrekdeveloperEnterprise Solution ArchitectAuthor Commented:
Bug fixed.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.