473,757 Members | 10,007 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Weird issue with System.NullRefe renceException

I am having a very strange issue with my asp.net application. I have
created a datagrid which dynamically gets populated from a person
choosing a value from a dropdown list and entering a quantity into a
text box (a simple version of a shopping cart). When I run/debug the
web page using the localhost in the page URL
(http://localhost/mypage.aspx), the datagrid updates properly when a
command button is clicked and all is well. However, when I run the web
page using the machinename (http://mymachine/mypage.aspx) I recieve the
error "Object Reference not Set...System.Nu llReferenceExce ption" when I
click the command button to update the datagrid with new values. Does
anyone have a solution as to why it works as localhost but does not as
machinename? And does anyone have a solution? Thanks in advance.
Shannon

Jul 21 '05 #1
2 1942
I think it would be helpful if you posted the code behind up.

Ciaran

"Shannon" <sh************ @state.co.us> wrote in message
news:11******** *************@c 13g2000cwb.goog legroups.com...
I am having a very strange issue with my asp.net application. I have
created a datagrid which dynamically gets populated from a person
choosing a value from a dropdown list and entering a quantity into a
text box (a simple version of a shopping cart). When I run/debug the
web page using the localhost in the page URL
(http://localhost/mypage.aspx), the datagrid updates properly when a
command button is clicked and all is well. However, when I run the web
page using the machinename (http://mymachine/mypage.aspx) I recieve the
error "Object Reference not Set...System.Nu llReferenceExce ption" when I
click the command button to update the datagrid with new values. Does
anyone have a solution as to why it works as localhost but does not as
machinename? And does anyone have a solution? Thanks in advance.
Shannon

Jul 21 '05 #2
Here is the requested code behind.

Imports System.Data.Sql Client
Public Class merchandise
Inherits System.Web.UI.P age

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents lblNavBar As System.Web.UI.W ebControls.Labe l
Protected WithEvents lblMerchandise As
System.Web.UI.W ebControls.Labe l
Protected WithEvents merTXT1 As System.Web.UI.W ebControls.Labe l
Protected WithEvents merTXT2 As System.Web.UI.W ebControls.Labe l
Protected WithEvents ddProducts As
System.Web.UI.W ebControls.Drop DownList
Protected WithEvents txtQty As System.Web.UI.W ebControls.Text Box
Protected WithEvents Label1 As System.Web.UI.W ebControls.Labe l
Protected WithEvents Label2 As System.Web.UI.W ebControls.Labe l
Protected WithEvents btnCart As
System.Web.UI.W ebControls.Link Button
Protected WithEvents dgCart As System.Web.UI.W ebControls.Data Grid
Protected WithEvents lblTotal As System.Web.UI.W ebControls.Labe l

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub

#End Region
Public objDT As System.Data.Dat aTable
Public objDR As System.Data.Dat aRow

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim dbConn As New
SqlConnection(C onfigurationSet tings.AppSettin gs("ConnectRWDa ta"))

'retrieve the data from the database for the List Box
Content
Dim daMerchandise As New SqlDataAdapter( "SELECT prodTYPE,
prodCOST, prodTYPE + ' - $' + CAST(prodCOST AS char(5)) AS prodLIST
FROM tblProducts", dbConn)

'fill the dataset
Dim dsmerchandise As New DataSet
daMerchandise.F ill(dsMerchandi se, "tblProduct s")

'fill the list box with the values.
ddProducts.Data Source = dsmerchandise.T ables("tblProdu cts")
ddProducts.Data TextField = "prodLIST"
ddProducts.Data ValueField = "prodCOST"
ddProducts.Data Bind()

'create the dynamic shopping cart table
makeCart()
End If
End Sub

Function makeCart()

objDT = New System.Data.Dat aTable("Cart")
objDT.Columns.A dd("ID", GetType(Integer ))
objDT.Columns(" ID").AutoIncrem ent = True
objDT.Columns(" ID").AutoIncrem entSeed = 1

objDT.Columns.A dd("Quantity", GetType(Integer ))
objDT.Columns.A dd("Product", GetType(String) )
objDT.Columns.A dd("Cost", GetType(Decimal ))

Session("Cart") = objDT
End Function

Public Sub AddToCart(ByVal s As Object, ByVal e As EventArgs)
objDT = Session("Cart")

Dim Product = ddProducts.Sele ctedItem.Text

objDR = objDT.NewRow 'this is the line creating the error when
run under machinename
objDR("Quantity ") = txtQty.Text
objDR("Product" ) = ddProducts.Sele ctedItem.Text
objDR("Cost") = Decimal.Parse(d dProducts.Selec tedItem.Value)
objDT.Rows.Add( objDR)
Session("Cart") = objDT

dgCart.DataSour ce = objDT
dgCart.DataBind ()

End Sub
End Class

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9143
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in system.windows.forms.dll
0
1358
by: Deutsche Dogge | last post by:
Hi. I'M having a weird problem with addign menuitems to a menu dynamically on the popup event of the menuitem containing the container of the menuitems i wanna add (tools -> external -> {list of items dynamically added}) All the code works #1 when only the MdiParent form is used, as soon as i open an MdiChild in it, right after the popup event returns, i get this error: ...
2
1721
by: Nicholas | last post by:
I have this class that provides a disk-based queue for storing various items. As items are queued the event delegate is called and the consumer dequeues the object and processes it. This seems to work off and on. Sometimes the queue does not pick up a queued item until another item is queued. Can anyone see a problem with this class? *** Here's the interface and EventArgs... *** /// <summary>
3
2111
by: Me | last post by:
I'm getting a NullReferenceException in Unknown Module when I follow the below steps to create a simple NotifyIcon app that creates the context menu on the fly(see a little analysis after the steps). 1. Create a new Windows Forms C# solution (I called mine DBChanger). 2. Replace Form1.cs code with this: -------------------- using System;
2
7839
by: Raed Sawalha | last post by:
i have a windows form(Main) with listview, when click an item in listview i open other window form (Sub) which generate the selected item from parent window in as treeview items when click any item in treeview i display the content item in axWebBrowser, i close the sub form normally when i close the main the following error is generated An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll ...
3
4889
by: Celebrate | last post by:
My application works fine when I run it locally but when I transfer it to our NEW Windows 2003 Web Edition server, I get a strange error. I've isolated the problem to when I issue a ConfigurationSettings.AppSettings call. My guess is, there's a security setting that I'm missing on my Server but what?? I've spend hours trying to debug this; help on this would be greatly appreciated... Here's the error I get:
2
312
by: Shannon | last post by:
I am having a very strange issue with my asp.net application. I have created a datagrid which dynamically gets populated from a person choosing a value from a dropdown list and entering a quantity into a text box (a simple version of a shopping cart). When I run/debug the web page using the localhost in the page URL (http://localhost/mypage.aspx), the datagrid updates properly when a command button is clicked and all is well. However,...
2
2781
by: Stephan Zaubzer | last post by:
Hi all, I encountered a problem with NumericUpDown yesterday and managed to reproduce the error with a very easy examle. I have a Windows Application with only one Form, which contains only one NumericUpDown control and nothing else. This is the only code I wrote: (everything else was done with the designer of Visual Studio).
1
2320
by: Tim_Mac | last post by:
hi, i am encountering a sporadic exception using crystal reports that is causing me grief, I can't 'handle' it... my code is loading a typed report, and loading a DataSet to it. unfortunately crystal reports customer support is very poor and their 'case management' tool refuses to function. i'm posting here in the hope that someone may have seen it before and worked around it. first of all, here is the exception:
0
9489
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9737
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.