| | |
Object reference not set to an instance of an object.
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 13
Reputation:
Solved Threads: 0
Im getting a NullReferenceException when I goto add a product to my cart, i get the error when i come to this part
I use extremely similar code in another one of my projects and do not come across this problem, I have also researched it for a while and still came across no soltuion.
Any help is appreciated!
ASP.NET Syntax (Toggle Plain Text)
cart.AddProduct(productnumber, name, price, prodQty, knobColor, finishColor)
I use extremely similar code in another one of my projects and do not come across this problem, I have also researched it for a while and still came across no soltuion.
ASP.NET Syntax (Toggle Plain Text)
Protected Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim cart As New Cart cart = Session("Cart") Dim flag As Integer = 1 Dim finishColor As String = "" Dim knobColor As String = "" Dim prodQty As Integer = 0 Dim price As Decimal = 0 Dim name As String = "" Dim productnumber As Integer = 0 If txtQty.Text <> "" And IsNumeric(txtQty.Text) Then prodQty = txtQty.Text flag = 0 Else lblError.Text = "Please enter a numeric quantity." Return End If productnumber = prodID name = lblName.Text price = lblPrice.Text prodQty = txtQty.Text finishColor = DDFinish.SelectedItem.Text knobColor = DDKnob.SelectedItem.Text cart.AddProduct(productnumber, name, price, prodQty, knobColor, finishColor) Session("Cart") = cart
•
•
Join Date: Apr 2008
Posts: 3
Reputation:
Solved Threads: 0
Session("Cart") is not initialized yet. So make sure You need to check Session("Cart") with null(nothing) and assign it properly. You need to do something like this.
Dim cart As New Cart
cart = Session("Cart")
if (cart == Nothing)
cart = new cart();
then use cart object. you won't get this type of error.
Dim cart As New Cart
cart = Session("Cart")
if (cart == Nothing)
cart = new cart();
then use cart object. you won't get this type of error.
•
•
•
•
Im getting a NullReferenceException when I goto add a product to my cart, i get the error when i come to this part
ASP.NET Syntax (Toggle Plain Text)
cart.AddProduct(productnumber, name, price, prodQty, knobColor, finishColor)
I use extremely similar code in another one of my projects and do not come across this problem, I have also researched it for a while and still came across no soltuion.
Any help is appreciated!ASP.NET Syntax (Toggle Plain Text)
Protected Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim cart As New Cart cart = Session("Cart") Dim flag As Integer = 1 Dim finishColor As String = "" Dim knobColor As String = "" Dim prodQty As Integer = 0 Dim price As Decimal = 0 Dim name As String = "" Dim productnumber As Integer = 0 If txtQty.Text <> "" And IsNumeric(txtQty.Text) Then prodQty = txtQty.Text flag = 0 Else lblError.Text = "Please enter a numeric quantity." Return End If productnumber = prodID name = lblName.Text price = lblPrice.Text prodQty = txtQty.Text finishColor = DDFinish.SelectedItem.Text knobColor = DDKnob.SelectedItem.Text cart.AddProduct(productnumber, name, price, prodQty, knobColor, finishColor) Session("Cart") = cart
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: Event Handler
- Next Thread: database access problem
| Thread Tools | Search this Thread |
.net 2.0 activexcontrol advice ajax alltypeofvideos application asp asp.net bc30451 bottomasp.net browser button c# c#gridviewcolumn checkbox click commonfunctions compatible confirmationcodegeneration content courier css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dynamically edit expose feedback fill flash form formatdecimal forms formview gridview homeedition hosting iframe iis javascript jquery listbox login microsoft mono mouse mssql multistepregistration news numerical objects opera panelmasterpagebuttoncontrols parent radio ratings registration reportemail rotatepage save schoolproject search security serializesmo.table silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking typeof unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webprogramming webservice xml xsl youareanotmemberofthedebuggerusers





