• Status: Solved
  • Priority: High
  • Security: Public
  • Views: 31
  • Last Modified:

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
0
Sudhanshum
Asked:
Sudhanshum
1 Solution
 
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

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now