Problem with class file
-
i got problems with my class file. most of the errors saying that 'Object reference not set to an instance of an object'. it looks like all functions in class file cannot be performed, even i do declare the class at code-behind file. do i have to call the class file in .aspx page? like this <%# Imports ... %>. this is page for CheckOut.aspx.vb.
Partial Class Checkout_CheckOut
Inherits System.Web.UI.PagePrivate order As Order Private cust As Customer Private cart As ShoppingCart Protected Sub Page\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load cart = Session("cart") If Session("order") Is Nothing Then order = New Order(DateTime.Now, Nothing, Session("cart")) Session("order") = order Else order = Session("order") cart = order.Cart End If cust = New Customer(txtEmail.Text, txtLastName.Text, txtFirstName.Text, \_ txtAddress.Text, txtCity.Text, txtState.Text, txtPostCode.Text, txtPhone.Text, \_ txtEmail.Text) order.Cust = cust lblSubtotal.Text = order.SubTotal.ToString("c") lblShipping.Text = order.Shipping.ToString("c") lblTotal.Text = order.Total.ToString("c") End Sub Protected Sub Wizard1\_FinishButtonClick(ByVal sender As Object, ByVal e As \_ System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick ' process credit card information here Dim success As Boolean success = OrderDB.WriteOrder(order) 'the function WriteOrder from OrderDB class Session("cart") = Nothing 'can't be performed Session("order") = Nothing If success Then Response.Redirect("Confirmation.aspx") Else Response.Redirect("Confirmation.aspx?Error=1") End If End Sub
End Class
-
i got problems with my class file. most of the errors saying that 'Object reference not set to an instance of an object'. it looks like all functions in class file cannot be performed, even i do declare the class at code-behind file. do i have to call the class file in .aspx page? like this <%# Imports ... %>. this is page for CheckOut.aspx.vb.
Partial Class Checkout_CheckOut
Inherits System.Web.UI.PagePrivate order As Order Private cust As Customer Private cart As ShoppingCart Protected Sub Page\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load cart = Session("cart") If Session("order") Is Nothing Then order = New Order(DateTime.Now, Nothing, Session("cart")) Session("order") = order Else order = Session("order") cart = order.Cart End If cust = New Customer(txtEmail.Text, txtLastName.Text, txtFirstName.Text, \_ txtAddress.Text, txtCity.Text, txtState.Text, txtPostCode.Text, txtPhone.Text, \_ txtEmail.Text) order.Cust = cust lblSubtotal.Text = order.SubTotal.ToString("c") lblShipping.Text = order.Shipping.ToString("c") lblTotal.Text = order.Total.ToString("c") End Sub Protected Sub Wizard1\_FinishButtonClick(ByVal sender As Object, ByVal e As \_ System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick ' process credit card information here Dim success As Boolean success = OrderDB.WriteOrder(order) 'the function WriteOrder from OrderDB class Session("cart") = Nothing 'can't be performed Session("order") = Nothing If success Then Response.Redirect("Confirmation.aspx") Else Response.Redirect("Confirmation.aspx?Error=1") End If End Sub
End Class
I can't make sense from the logic, nor do I know what your class objects look like. But, in the page load event, it appears that not all objects have the chance of being instantiated. Customer - this is always created Order - creates a new object unless found in the session object. Cart - Never creates a new instance and assumes there will always be a "cart" object in session object. The easiest way is to put a break point on your code and see where it blows up.. :wtf: