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
<%@ 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>

Open in new window


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

Open in new window


Note: The insert works correctly in the database but I still receive the error that Button1_Click is undefined.
derrekdeveloperAsked:
Who is Participating?
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:
Hi,

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" />
0

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
derrekdeveloperAuthor Commented:
Thanks Lokesh. Just changed it and the bug went away.
0
derrekdeveloperAuthor Commented:
Bug fixed.
0
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
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.