asp.net DropDownList postback not executing method on first postback

74 views Asked by At

I'm facing very un natural problem suddenly. I have DropDownList with autopostback is true. Postback executes a method which populates other things onpage according to selection. Now When I select any value first time from that dropdown then page gets postback but nothing get populate but from second time it works fine. Even I put breakpoint on that dropdown & it's not even hitting breakpoint for first postback.

<asp:DropDownList ID="ClientCode" runat="server" ClientIDMode="Static" CssClass="field-pitch" AutoPostBack="true"></asp:DropDownList>

Private Sub ClientCode_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ClientCode.SelectedIndexChanged
        Me.populateConsignerDetails()
End Sub

Private Sub populateConsignerDetails()
        Try
            Dim str As String = "SELECT * FROM clientsDetails WHERE clientID = @clientID"
            con.Open()
            Dim cmd As New MySqlCommand(str, con)
            cmd.Parameters.AddWithValue("@clientID", ClientCode.SelectedItem.ToString)
            Dim da As New MySqlDataAdapter(cmd)
            Dim dt As New DataTable
            da.Fill(dt)
            con.Close()
            Dim payingParty As String = String.Empty
            If dt.Rows.Count > 0 Then

                consignerName.Text = dt.Rows(0)("clientName").ToString
                consignerAddress.Text = dt.Rows(0)("companyAddress").ToString
                consignerMobile1.Text = dt.Rows(0)("contactNumber1").ToString
                consignerCity.Text = dt.Rows(0)("city").ToString
                consignerState.Text = dt.Rows(0)("state").ToString
                consignerPinCode.Text = dt.Rows(0)("pinCode").ToString
            End If
        Catch ex As Exception
            Response.Write(ex)
        End Try
    End Sub

Update

Private Sub myadmin_shipment_details2_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then
            populateClient()
        End If
End Sub

Private Sub populateClient()
        Using conn As New MySqlConnection()
            conn.ConnectionString = ConfigurationManager _
                .ConnectionStrings("conio").ConnectionString()
            Using cmd As New MySqlCommand()
                cmd.CommandText = "Select * from clientsDetails where status = 'active'"
                cmd.Connection = conn
                conn.Open()
                Using sdr As MySqlDataReader = cmd.ExecuteReader()
                    While sdr.Read()
                        Dim item As New ListItem()
                        item.Text = sdr("clientID").ToString()
                        item.Value = sdr("ClientName").ToString()
                        ClientCode.Items.Add(item)
                    End While
                End Using
                conn.Close()
            End Using
        End Using
    End Sub
0

There are 0 answers