Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 381
  • Last Modified:

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
0
Seven price
Asked:
Seven price
  • 2
  • 2
3 Solutions
 
spprivateCommented:
can you post the code behind and aspx pages
0
 
Seven priceFull StackAuthor Commented:
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

0
 
Anurag ThakurTechnical ManagerCommented:
do you want to call the shoppingcart2 function/method everytime the postback occurs or only once
if everytime then its ok else write it in the page.ispostback == false section
0
 
spprivateCommented:
Right
that way the control is created and events are wired once.
0
 
Seven priceFull StackAuthor Commented:
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.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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