Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem with class file

Problem with class file

Scheduled Pinned Locked Moved ASP.NET
helpdesignsalesquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    miss nadia
    wrote on last edited by
    #1

    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.Page

    Private 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

    D 1 Reply Last reply
    0
    • M miss nadia

      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.Page

      Private 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

      D Offline
      D Offline
      doWhileSomething
      wrote on last edited by
      #2

      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:

      My Personal Site

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups