Link to home
Start Free TrialLog in
Avatar of Seven price
Seven priceFlag for United States of America

asked on

ASP.NET VB, need to press a button twice to make something happen.

I got a web application, the problem is that the text in the label will not update on the first click, I need to click the button twice, I debugged to code, and I found out that the label does not receive the data until after the second click,
the button is built programatically

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ASKER CERTIFIED SOLUTION
Avatar of spprivate
spprivate
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Seven price

ASKER

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call ShoppingCart2()
End sub
####################################reader ##########
Public Function ShoppingCart2()
While sqlDR.Read
            Dim btn As New Button
            btn.Text = "Update" '& i
            btn.ID = "mybutton" + cnt.ToString()
            AddHandler btn.Click, AddressOf Btn_Click
            c.Controls.Add(btn)
            r.Controls.Add(c)

end while
End sub



###################### onclick button ##############
 Private Sub Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
 Dim q As String = CType(FindControl("PrId" + value4), TextBox).Text
            Dim h As String = CType(IfFindControl("txtquantity" + value4), TextBox).Text
If  ShoppingCartCompare(h) true Then
Response.write("good")
else
Response.write("bad")
end if

  compare here
Public Function ShoppingCartCompare(ByVal ItemsLeft As String)
        Dim UserId As String 
        Dim conn As New SqlConnection(("ConnString"))
        Dim cmd As New SqlCommand
 
        cmd = New SqlCommand("spA1SCheckquantity", conn)
 
        Dim prm As New SqlParameter("@UserId", SqlDbType.VarChar, 15)
        cmd.CommandType = CommandType.StoredProcedure
        prm.Value = UserId
        cmd.Parameters.Add(prm)
        cmd.CommandType = CommandType.StoredProcedure
        Dim cnt As Integer = 0
        Dim cnt2 As Integer = 0
        Dim sqlDR As SqlDataReader
        conn.Open()
        sqlDR = cmd.ExecuteReader
 
        While sqlDR.Read
            If sqlDR("ItemsLeft") <= sqlDR("Quantity") Then
                ShoppingCartCompare = True
 
            Else
                ShoppingCartCompare = False
 
            End If
        End While
        conn.Close()
    End Function

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Actually I just added it to the  select statement for the validation check. But I will keep this one in my library for future reference.
Thanks.