Yury Merezhkov
asked on
Button click doesn't update number
Hi guys,
I have the following code for my item.aspx page. User clicks on the Add to Shopping Cart button. Record gets inserted in shopping cart table. The shopping cart link is supposed to change to Shopping Cart (Number_of_items_in_cart_h ere). But it doesn't change unless I go to another page after clicking the button or refresh page. How do I make that change after the first click? Inserting in the table works fine. I added master page code that actually checks for number of items in shopping cart table. Basically, itemsInCart var doesn't get updated after the button was clicked. It updates only after I navigate to some other page or refresh item.aspx. I guess there is a problem with my master page. Please help.
Thanks.
I have the following code for my item.aspx page. User clicks on the Add to Shopping Cart button. Record gets inserted in shopping cart table. The shopping cart link is supposed to change to Shopping Cart (Number_of_items_in_cart_h
Thanks.
item.aspx:
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\titanmusic.accdb;Persist Security Info=True"
Dim objConnection As New System.Data.OleDb.OleDbConnection(strConn)
Dim strSQL As String = "INSERT INTO Cart (SessionID, ProductFK1) VALUES ('" & Session.SessionID & _
"', " & DetailsView1.DataKey.Value & ")"
Dim objCommand As New System.Data.OleDb.OleDbCommand(strSQL, objConnection)
Try
objConnection.Open()
Try
objCommand.ExecuteNonQuery()
Catch ex As Exception
MsgBox(Err.Number & " " & Err.Description)
Finally
objConnection.Close()
End Try
Catch ex As Exception
MsgBox(Err.Number & " " & Err.Description)
End Try
End Sub
Master Page:
Public itemsInCart As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Session("SCart") = "CartSession"
Dim ctl As Control
Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\titanmusic.accdb;Persist Security Info=True"
Dim objConnection As New System.Data.OleDb.OleDbConnection(strConn)
Dim strSQL As String = "SELECT COUNT(*) FROM Cart WHERE SessionID='" & Session.SessionID & "'"
Dim objCommand As New System.Data.OleDb.OleDbCommand(strSQL, objConnection)
Try
objConnection.Open()
itemsInCart = objCommand.ExecuteScalar
objConnection.Close()
Catch ex As Exception
MsgBox("Connection failed to open. Error: " & ex.ToString())
End Try
End Sub
<%
If itemsInCart = 0 Then
Response.Write("Shopping Cart")
Else
Response.Write("Shopping Cart (" & itemsInCart & ")")
End If
%>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER