Dynamic textbox's textbox change event calling on button click

Hi I am creating dynamic textbox with textchange event, When i change text then textchange is calling fine but when I hit on button then before button click that textchange event is called, I am not sure why it is calling. Please help
SudhanshumAsked:
Who is Participating?

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

x
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.

sammySeltzerCommented:
Hi,
Your question is not very clear. Can you show the code you are using?

Here is how I use textchanged event:

         //Markup:
                     <label id="lblEmpID">
                            <span style="font-weight: bold; font-size: 16px; color: #000000;">Enter your Employee Id to begin</span><span
                                style="color: #ff0000">*</span></label>
                        <asp:TextBox ID="txtEmpID" maxlength="10" placeholder="Badge ID..." Style="width: 150px;" class="form-control"
                            runat="server" AutoPostBack="true" OnTextChanged="txtEmpID_TextChanged"></asp:TextBox>

Open in new window


Then
C#
    Protected Sub txtEmpID_TextChanged(sender As Object, e As EventArgs) Handles txtEmpID.TextChanged
        If Not String.IsNullOrEmpty(txtEmpID.Text) Then
            Dim Conn As SqlConnection
            'Read in connection String
            Conn = New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
            Conn.Open()
            Dim cmd As New SqlCommand("ValidateEmpID", Conn)
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Parameters.AddWithValue("@empID", txtEmpID.Text)
            Dim dr As SqlDataReader = cmd.ExecuteReader()
            If dr.HasRows Then
                'Employee exists'
                dr.Read()
                checkusername.Visible = True
                dprocessed.Visible = True
                If dr("previousYear").ToString() = "1" Then
                    imgstatus.ImageUrl = "images/NotAvailable.jpg"
                    lblStatus.Text = "Please verify your information for accuracy. Then complete rest of the form."
                    lblStatus.ForeColor = System.Drawing.Color.Red
                    System.Threading.Thread.Sleep(300)
                    txteName.Text = dr("employeeName").ToString()
                    txttitle.Text = dr("empTitle").ToString()
                    txtemail.Text = dr("email").ToString()
                    txtEmpID.Text = dr("empID").ToString()

                ElseIf dr("thisYear").ToString() = "1" Then
                    imgstatus.ImageUrl = "images/NotAvailable.jpg"
                    lblStatus.Text = "You have already completed this form. Please close the form. If you feel there is a mistake, please contact administrator at xxx-xxx-xxxx"
                    lblStatus.ForeColor = System.Drawing.Color.Red
                    System.Threading.Thread.Sleep(300)
                    txteName.Text = dr("employeeName").ToString()
                    txttitle.Text = dr("empTitle").ToString()
                    txtemail.Text = dr("email").ToString()
                    txtEmpID.Text = dr("empID").ToString()
                    txteName.Enabled = False
                    txttitle.Enabled = False
                    txtemail.Enabled = False
                    txtEmpID.Enabled = False
                    GridPanels.Enabled = False
                    dprocessed.Visible = True
                    btnNext.Enabled = False
                Else
                    'not this year, nor the previous year'
                End If
            Else
                checkusername.Visible = True
                dprocessed.Visible = True
                imgstatus.ImageUrl = "images/Icon_Available.gif"
                lblStatus.Text = "Proceed to complete entire form"
                lblStatus.ForeColor = System.Drawing.Color.Red
                System.Threading.Thread.Sleep(300)
                txteName.Text = ""
                txttitle.Text = ""
                txtemail.Text = ""
            End If
        Else
            checkusername.Visible = False
        End If
    End Sub

Open in new window


Obviously, I am doing a lot more with mine but if you show your code, we can take a look or you can modify this to suit your need.

It is not affected by button 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
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.