Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object reference not set to an instance of an object

Status
Not open for further replies.

byrne1

Programmer
Aug 7, 2001
415
US
I get this error message when I try to run my ASP.NET application on my client's server. It works fine on my PC and I get no errors when I run it in debug mode. Please help!

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
Payroll_Application.NewRecord.ApplyTemplate(Object sender, EventArgs e)
Payroll_Application.NewRecord.Page_Load(Object sender, EventArgs e)
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +29
System.Web.UI.Page.ProcessRequestMain() +724




I've copied the necessary snippets of code below.



<asp:dropdownlist id=&quot;ddlDebtType&quot; AutoPostBack=&quot;True&quot; Runat=&quot;server&quot; OnSelectedIndexChanged=&quot;ApplyTemplate&quot;></asp:dropdownlist>

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ddlDebtType.Items.Add(&quot;Loan&quot;)
ddlDebtType.Items.Add(&quot;Advance&quot;)
ddlDebtType.Items.Add(&quot;Prepay&quot;)
ddlDebtType.Items.Add(&quot;Mutual&quot;)
End Sub

Public Sub ApplyTemplate(ByVal sender As System.Object, ByVal e As System.EventArgs)
'all code in this sub has been commented out for debugging purposes, but I still get the error
End Sub
 
I've narrowed this error down to the following line of code:

Select Case Trim(ddlDebtType.SelectedItem.Value)

It happens when I try to reference a DDL in a sub on my page. This DDL is not in a datagrid, and it works fine on my development PC. I have other pages that have DDLs on them and they work fine (so I can rule out a problem with the .NET framework).


<asp:dropdownlist id=&quot;ddlDebtType&quot; AutoPostBack=&quot;True&quot; Runat=&quot;server&quot; OnSelectedIndexChanged=&quot;ApplyTemplate&quot;></asp:dropdownlist>

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ddlDebtType.Items.Add(&quot;Loan&quot;)
ddlDebtType.Items.Add(&quot;Advance&quot;)
ddlDebtType.Items.Add(&quot;Prepay&quot;)
ddlDebtType.Items.Add(&quot;Mutual&quot;)
ApplyTemplate(sender, e)
End Sub

Public Sub ApplyTemplate(ByVal sender As System.Object, ByVal e As System.EventArgs)
Select Case Trim(ddlDebtType.SelectedItem.Value)
Case &quot;Loan&quot;
Case &quot;Advance&quot;
Case &quot;Prepay&quot;
Case &quot;Mutual&quot;
End Select
End Sub
 
This may be entirely too simplistic, but are you using a code behind page? If so, it is possible that you don't have the newest copy of the .aspx page on the server, and the .vb file is trying to access a DDL that doesn't exist. This would explain why it works on your development PC.

Just a thought! Kevin B.
.Net Programmer [thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top