Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variables with User Controls 1

Status
Not open for further replies.

MikeMCSD

MIS
Jul 12, 2002
107
US
I'm trying to get 2 variables to "refresh" on the top part of the
page when a function is called that updates them.

I want to keep the "total number of items" and "total amount" for the shopping cart
updated on the Default.aspx page to the current values whenever they are changed.

On the Page_Load of Default.aspx, I load different user controls into the Body like:

Dim control As Control
control = Page.LoadControl("UserControls/selected_page_here.ascx")
pageContentsCell.Controls.Add(control)

items.Text = Session("items")
total.Text = Session("total")

in .aspx:
<td id="pageContentsCell" runat="server">

<asp:Label Runat=server ID="total"></asp:Label>
<asp:Label Runat=server ID="items"></asp:Label>


The problem is when "Add to Cart" is clicked, the variables are not updated
(I don't display the shopping cart when Add to Cart is clicked):

Private Sub Add to Cart

Session("items") = cartHead.Total_Items
Session("total") = String.Format("{0:c}", cartHead.Total_Amount)

End Sub

But if Add to Cart is clicked a second time, the variables update - but with the
values of the first time it was clicked.
I'm guessing it is something with the post back.

Any ideas?
Thanks
 
what have you written in the onClick event of the Add to Cart button?

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
what have you written in the onClick event of the Add to Cart button? "
I don't have an onClick event for the button,
the button is in a DataList and I'm using:

Private Sub list_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles list.ItemCommand

after I add the item to the cart, I do this:

Session("items") = cartHead.items
Session("total") = String.Format("{0:c}", cartHead.amt)

but these variables aren't updated in Default.aspx, which is the page the user control is contained in.

 
I found a solution by added
Response.Redirect(Request.RawUrl):

Private Sub Add to Cart
.
.
Session("items") = cartHead.Total_Items
Session("total") = String.Format("{0:c}", cartHead.amt)

Response.Redirect(Request.RawUrl)

End Sub

This reloads the page and forces another Page_Load and resets the variable to the current values.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top