Passing Value from session into a usercontrol

M

Microsoft

I have the following sub inside a usercontrol that is called when a
hyperlink is loaded using the OnLoad = hlViewCart_Load (below) that accesses
a session variable to get the text for the link but, I get the following
error:

Object reference not set to an instance of an object.

Public Sub hlViewCart_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles hlViewCart.Load
Dim sessionCart As DataTable = CType(Session("cart"), DataTable)
Dim dtCount As String = CStr(sessionCart.Rows.Count())
hlViewCart.Text = "View Cart " & dtCount & " Items"
End Sub

When I remove the dtCount the hlViewCart.Text is passed correctly. In other
words it works correctly as long as I dont access the count of the rows of
the datatable stored in the session. I want the view cart link to reflect
the total number of items in the cart "View Cart (3 - Items)"

TIA,

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top