Error while using "State Bags".

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Hrishi R (HrishiR_at_discussions.microsoft.com)
Date: 11/16/04


Date: Mon, 15 Nov 2004 22:19:02 -0800

Hi:

The following ASP.NET code segment throws an "Object reference not set to an
instance of an object" exception.
------------------
Public Sub Page_Load(Source As Object, E As EventArgs)

  Dim viewCount As Integer

  If ViewState("viewCount").ToString() = "" Then
     viewCount = 1
  Else
  viewCount = CType(ViewState("viewCount"), Integer) + 1
  End If
  labelViews.Text = "Times page has been viewed: " & viewCount.ToString()

  ViewState("viewCount") = viewCount
-------------
Please help, i can find many references to this exception on MSDN but none
seems to help.

Thanks.



Relevant Pages

  • Re: Object reference not set to an instance of an object
    ... I cannot answer why it would happen in one environment and not in another, ... Auction002.login.btnLogin_Click(Object sender, EventArgs e) ... Otherwise, you can use Try/Catch to catch the exception, and perhaps ... > Object reference not set to an instance of an object. ...
    (microsoft.public.dotnet.framework.aspnet)
  • AJAX Problem
    ... I am trying to use cascadingdropdown AJAX control but it gives me ... Object reference not set to an instance of an object. ... Exception Details: System.NullReferenceException: Object reference not ... sender, EventArgs e) +96 ...
    (microsoft.public.dotnet.framework.aspnet)
  • Object reference not set to an instance of an object.
    ... Object reference not set to an instance of an object. ... An unhandled exception occurred during the execution of the ... Dim myJobRequest As New skillsDB.jobRequest ... Session= "The skills database has been updated ...
    (microsoft.public.dotnet.general)
  • Re: Exchange 2003 Mobile Admin
    ... Object reference not set to an instance of an object. ... Please review the stack trace for more information about ... Exception Details: System.NullReferenceException: Object reference not set ... Server Error in '/MobileAdmin' Application. ...
    (microsoft.public.exchange.setup)
  • Missing component causing error in IIS hosted webpage
    ... Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. ... Information regarding the origin and location of the exception can be identified using the exception stack trace below. ... System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15 ...
    (microsoft.public.windowsxp.embedded)