Professional Web Applications Themes

Mysterious Error: Object reference not set to an instance of an object - ASP.NET Building Controls

Hi There! I'm having a mysterious error right after I login using Forms Authentication in my ASP.NET app. Below is the error... Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. The exception throws at the code that tries to set a property (String data type) at my Menu user control. When I refresh the page, the page render successfully without any exceptions! Why?? My conclusion is that there are no exceptions in the first place. I can't think why ASP.NET throws the exception when I access the page for first time but not the second ...

  1. #1

    Default Mysterious Error: Object reference not set to an instance of an object

    Hi There!

    I'm having a mysterious error right after I login using Forms Authentication
    in my ASP.NET app. Below is the error...

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

    The exception throws at the code that tries to set a property (String data
    type) at my Menu user control.

    When I refresh the page, the page render successfully without any
    exceptions! Why?? My conclusion is that there are no exceptions in the first
    place. I can't think why ASP.NET throws the exception when I access the page
    for first time but not the second time! This exception is totally
    unpredictable and unreasonable!

    Plz help!!!

    My SYS specs are...
    - ASP.NET 1.1
    - Windows XP (This error also occurs on Windows 2000 and Windows Server 2003
    as well)

    Thank you all in advance.

    Max


    Max Guest

  2. #2

    Default RE: Mysterious Error: Object reference not set to an instance of an ob

    Probably not going to help, but I had a similar issue when trying to access
    public properties of a web user control (I think thats what it's called... an
    ASCX control).

    For some reason the control wasn't be instantiated correctly, or posted back
    to correctly.

    I created a second page exactly in the same manner as the first, copied the
    code and it worked. I deleted the first page, renamed the 2nd to the right
    name and moved on.

    If you make a brand new page w/ nothing but your control on it does it fail
    as well?


    "Max" wrote:
    > Hi There!
    >
    > I'm having a mysterious error right after I login using Forms Authentication
    > in my ASP.NET app. Below is the error...
    >
    > Exception Details: System.NullReferenceException: Object reference not set
    > to an instance of an object.
    >
    > The exception throws at the code that tries to set a property (String data
    > type) at my Menu user control.
    >
    > When I refresh the page, the page render successfully without any
    > exceptions! Why?? My conclusion is that there are no exceptions in the first
    > place. I can't think why ASP.NET throws the exception when I access the page
    > for first time but not the second time! This exception is totally
    > unpredictable and unreasonable!
    >
    > Plz help!!!
    >
    > My SYS specs are...
    > - ASP.NET 1.1
    > - Windows XP (This error also occurs on Windows 2000 and Windows Server 2003
    > as well)
    >
    > Thank you all in advance.
    >
    > Max
    >
    >
    >
    cmay Guest

  3. #3

    Default Re: Mysterious Error: Object reference not set to an instance of an object

    The NullReferenceException indicates that you are referencing an object in a
    line of code, and that the object is null, or Nothing. It is not
    instantiated. If you post the line of code which throws the exception, I can
    tell you all of the object references in the line of code which may or may
    not be null. After that, it will be up to you to determine which, and why.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Neither a follower nor a lender be.

    "Max" <zeromaxdot.com.com> wrote in message
    news:Ox7ss%23U8EHA.3236TK2MSFTNGP15.phx.gbl...
    > Hi There!
    >
    > I'm having a mysterious error right after I login using Forms
    > Authentication in my ASP.NET app. Below is the error...
    >
    > Exception Details: System.NullReferenceException: Object reference not set
    > to an instance of an object.
    >
    > The exception throws at the code that tries to set a property (String data
    > type) at my Menu user control.
    >
    > When I refresh the page, the page render successfully without any
    > exceptions! Why?? My conclusion is that there are no exceptions in the
    > first place. I can't think why ASP.NET throws the exception when I access
    > the page for first time but not the second time! This exception is totally
    > unpredictable and unreasonable!
    >
    > Plz help!!!
    >
    > My SYS specs are...
    > - ASP.NET 1.1
    > - Windows XP (This error also occurs on Windows 2000 and Windows Server
    > 2003 as well)
    >
    > Thank you all in advance.
    >
    > Max
    >

    Kevin Spencer Guest

  4. #4

    Default Re: Mysterious Error: Object reference not set to an instance of an object

    Inside the Page_Load function on the page i believe there is a
    if(!Page.IsPostBack)
    that is loading the Object. Look there.



    Kevin Spencer wrote:
    > The NullReferenceException indicates that you are referencing an
    object in a
    > line of code, and that the object is null, or Nothing. It is not
    > instantiated. If you post the line of code which throws the
    exception, I can
    > tell you all of the object references in the line of code which may
    or may
    > not be null. After that, it will be up to you to determine which, and
    why.
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > .Net Developer
    > Neither a follower nor a lender be.
    >
    > "Max" <zeromaxdot.com.com> wrote in message
    > news:Ox7ss%23U8EHA.3236TK2MSFTNGP15.phx.gbl...
    > > Hi There!
    > >
    > > I'm having a mysterious error right after I login using Forms
    > > Authentication in my ASP.NET app. Below is the error...
    > >
    > > Exception Details: System.NullReferenceException: Object reference
    not set
    > > to an instance of an object.
    > >
    > > The exception throws at the code that tries to set a property
    (String data
    > > type) at my Menu user control.
    > >
    > > When I refresh the page, the page render successfully without any
    > > exceptions! Why?? My conclusion is that there are no exceptions in
    the
    > > first place. I can't think why ASP.NET throws the exception when I
    access
    > > the page for first time but not the second time! This exception is
    totally
    > > unpredictable and unreasonable!
    > >
    > > Plz help!!!
    > >
    > > My SYS specs are...
    > > - ASP.NET 1.1
    > > - Windows XP (This error also occurs on Windows 2000 and Windows
    Server
    > > 2003 as well)
    > >
    > > Thank you all in advance.
    > >
    > > Max
    > >
    Navajo Boy Guest

  5. #5

    Default Re: Mysterious Error: Object reference not set to an instance of an object

    Are you the same person who asked the original question? If so, you need to
    post the offending line of code. If not, what the heck are you talking
    about?

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Neither a follower nor a lender be.

    "Navajo Boy" <navajonikeboyrocketmail.com> wrote in message
    news:1104765844.492129.251700c13g2000cwb.googlegr oups.com...
    > Inside the Page_Load function on the page i believe there is a
    > if(!Page.IsPostBack)
    > that is loading the Object. Look there.
    >
    >
    >
    > Kevin Spencer wrote:
    >> The NullReferenceException indicates that you are referencing an
    > object in a
    >> line of code, and that the object is null, or Nothing. It is not
    >> instantiated. If you post the line of code which throws the
    > exception, I can
    >> tell you all of the object references in the line of code which may
    > or may
    >> not be null. After that, it will be up to you to determine which, and
    > why.
    >>
    >> --
    >> HTH,
    >>
    >> Kevin Spencer
    >> Microsoft MVP
    >> .Net Developer
    >> Neither a follower nor a lender be.
    >>
    >> "Max" <zeromaxdot.com.com> wrote in message
    >> news:Ox7ss%23U8EHA.3236TK2MSFTNGP15.phx.gbl...
    >> > Hi There!
    >> >
    >> > I'm having a mysterious error right after I login using Forms
    >> > Authentication in my ASP.NET app. Below is the error...
    >> >
    >> > Exception Details: System.NullReferenceException: Object reference
    > not set
    >> > to an instance of an object.
    >> >
    >> > The exception throws at the code that tries to set a property
    > (String data
    >> > type) at my Menu user control.
    >> >
    >> > When I refresh the page, the page render successfully without any
    >> > exceptions! Why?? My conclusion is that there are no exceptions in
    > the
    >> > first place. I can't think why ASP.NET throws the exception when I
    > access
    >> > the page for first time but not the second time! This exception is
    > totally
    >> > unpredictable and unreasonable!
    >> >
    >> > Plz help!!!
    >> >
    >> > My SYS specs are...
    >> > - ASP.NET 1.1
    >> > - Windows XP (This error also occurs on Windows 2000 and Windows
    > Server
    >> > 2003 as well)
    >> >
    >> > Thank you all in advance.
    >> >
    >> > Max
    >> >
    >

    Kevin Spencer Guest

  6. #6

    Default Re: Mysterious Error: Object reference not set to an instance of a

    I think Navajo is right... the problem lies in 'if(!Page.IsPostBack)' of
    Page_Load().
    ...... whenever any control does a postback it goes through the
    Page_Load() again. So the code that we donot want to run on every postback we
    give in 'if(!Page.IsPostBack) {...}'. The code inside this loop only executes
    when the page is loaded for the first time or an equivalent situation when we
    refresh the page. I think thts where your problem lies Max. I think you are
    initialising the menu control inside this if loop and somehow somewhere your
    menu control loses its value, b4 coming back to page_load() on some postback.
    And when it comes there its does not initialise the menu control as this code
    is inside the if loop and it goes inside the if loop only when its not a
    postback.
    If you are initialising menu control in Page_Load() inside the
    'if(!Page.IsPostBack)' try doing it outside this loop.
    I am not very sure of your problem but if what I think your problem is is
    correct then I guess this should work.


    "Kevin Spencer" wrote:
    > Are you the same person who asked the original question? If so, you need to
    > post the offending line of code. If not, what the heck are you talking
    > about?
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > ..Net Developer
    > Neither a follower nor a lender be.
    >
    > "Navajo Boy" <navajonikeboyrocketmail.com> wrote in message
    > news:1104765844.492129.251700c13g2000cwb.googlegr oups.com...
    > > Inside the Page_Load function on the page i believe there is a
    > > if(!Page.IsPostBack)
    > > that is loading the Object. Look there.
    > >
    > >
    > >
    > > Kevin Spencer wrote:
    > >> The NullReferenceException indicates that you are referencing an
    > > object in a
    > >> line of code, and that the object is null, or Nothing. It is not
    > >> instantiated. If you post the line of code which throws the
    > > exception, I can
    > >> tell you all of the object references in the line of code which may
    > > or may
    > >> not be null. After that, it will be up to you to determine which, and
    > > why.
    > >>
    > >> --
    > >> HTH,
    > >>
    > >> Kevin Spencer
    > >> Microsoft MVP
    > >> .Net Developer
    > >> Neither a follower nor a lender be.
    > >>
    > >> "Max" <zeromaxdot.com.com> wrote in message
    > >> news:Ox7ss%23U8EHA.3236TK2MSFTNGP15.phx.gbl...
    > >> > Hi There!
    > >> >
    > >> > I'm having a mysterious error right after I login using Forms
    > >> > Authentication in my ASP.NET app. Below is the error...
    > >> >
    > >> > Exception Details: System.NullReferenceException: Object reference
    > > not set
    > >> > to an instance of an object.
    > >> >
    > >> > The exception throws at the code that tries to set a property
    > > (String data
    > >> > type) at my Menu user control.
    > >> >
    > >> > When I refresh the page, the page render successfully without any
    > >> > exceptions! Why?? My conclusion is that there are no exceptions in
    > > the
    > >> > first place. I can't think why ASP.NET throws the exception when I
    > > access
    > >> > the page for first time but not the second time! This exception is
    > > totally
    > >> > unpredictable and unreasonable!
    > >> >
    > >> > Plz help!!!
    > >> >
    > >> > My SYS specs are...
    > >> > - ASP.NET 1.1
    > >> > - Windows XP (This error also occurs on Windows 2000 and Windows
    > > Server
    > >> > 2003 as well)
    > >> >
    > >> > Thank you all in advance.
    > >> >
    > >> > Max
    > >> >
    > >
    >
    >
    >
    Yatendra Khandelwal Guest

  7. #7

    Default Re: Mysterious Error: Object reference not set to an instance of a

    but yeah one should be really cautious putting some code outside
    'if(!Page.IsPostBack)' as it may have negetive impact on performance.


    "Yatendra Khandelwal" wrote:
    > I think Navajo is right... the problem lies in 'if(!Page.IsPostBack)' of
    > Page_Load().
    > ...... whenever any control does a postback it goes through the
    > Page_Load() again. So the code that we donot want to run on every postback we
    > give in 'if(!Page.IsPostBack) {...}'. The code inside this loop only executes
    > when the page is loaded for the first time or an equivalent situation when we
    > refresh the page. I think thts where your problem lies Max. I think you are
    > initialising the menu control inside this if loop and somehow somewhere your
    > menu control loses its value, b4 coming back to page_load() on some postback.
    > And when it comes there its does not initialise the menu control as this code
    > is inside the if loop and it goes inside the if loop only when its not a
    > postback.
    > If you are initialising menu control in Page_Load() inside the
    > 'if(!Page.IsPostBack)' try doing it outside this loop.
    > I am not very sure of your problem but if what I think your problem is is
    > correct then I guess this should work.
    >
    >
    > "Kevin Spencer" wrote:
    >
    > > Are you the same person who asked the original question? If so, you need to
    > > post the offending line of code. If not, what the heck are you talking
    > > about?
    > >
    > > --
    > > HTH,
    > >
    > > Kevin Spencer
    > > Microsoft MVP
    > > ..Net Developer
    > > Neither a follower nor a lender be.
    > >
    > > "Navajo Boy" <navajonikeboyrocketmail.com> wrote in message
    > > news:1104765844.492129.251700c13g2000cwb.googlegr oups.com...
    > > > Inside the Page_Load function on the page i believe there is a
    > > > if(!Page.IsPostBack)
    > > > that is loading the Object. Look there.
    > > >
    > > >
    > > >
    > > > Kevin Spencer wrote:
    > > >> The NullReferenceException indicates that you are referencing an
    > > > object in a
    > > >> line of code, and that the object is null, or Nothing. It is not
    > > >> instantiated. If you post the line of code which throws the
    > > > exception, I can
    > > >> tell you all of the object references in the line of code which may
    > > > or may
    > > >> not be null. After that, it will be up to you to determine which, and
    > > > why.
    > > >>
    > > >> --
    > > >> HTH,
    > > >>
    > > >> Kevin Spencer
    > > >> Microsoft MVP
    > > >> .Net Developer
    > > >> Neither a follower nor a lender be.
    > > >>
    > > >> "Max" <zeromaxdot.com.com> wrote in message
    > > >> news:Ox7ss%23U8EHA.3236TK2MSFTNGP15.phx.gbl...
    > > >> > Hi There!
    > > >> >
    > > >> > I'm having a mysterious error right after I login using Forms
    > > >> > Authentication in my ASP.NET app. Below is the error...
    > > >> >
    > > >> > Exception Details: System.NullReferenceException: Object reference
    > > > not set
    > > >> > to an instance of an object.
    > > >> >
    > > >> > The exception throws at the code that tries to set a property
    > > > (String data
    > > >> > type) at my Menu user control.
    > > >> >
    > > >> > When I refresh the page, the page render successfully without any
    > > >> > exceptions! Why?? My conclusion is that there are no exceptions in
    > > > the
    > > >> > first place. I can't think why ASP.NET throws the exception when I
    > > > access
    > > >> > the page for first time but not the second time! This exception is
    > > > totally
    > > >> > unpredictable and unreasonable!
    > > >> >
    > > >> > Plz help!!!
    > > >> >
    > > >> > My SYS specs are...
    > > >> > - ASP.NET 1.1
    > > >> > - Windows XP (This error also occurs on Windows 2000 and Windows
    > > > Server
    > > >> > 2003 as well)
    > > >> >
    > > >> > Thank you all in advance.
    > > >> >
    > > >> > Max
    > > >> >
    > > >
    > >
    > >
    > >
    Yatendra Khandelwal Guest

  8. #8

    Default Re: Mysterious Error: Object reference not set to an instance of an ob

    I did that and the same exception thrown when I refresh the page repadily.

    max

    "cmay" <cmaydiscussions.microsoft.com> wrote in message
    news:B5327ADF-363F-4442-B904-D1E877D03E0Bmicrosoft.com...
    > Probably not going to help, but I had a similar issue when trying to
    > access
    > public properties of a web user control (I think thats what it's called...
    > an
    > ASCX control).
    >
    > For some reason the control wasn't be instantiated correctly, or posted
    > back
    > to correctly.
    >
    > I created a second page exactly in the same manner as the first, copied
    > the
    > code and it worked. I deleted the first page, renamed the 2nd to the
    > right
    > name and moved on.
    >
    > If you make a brand new page w/ nothing but your control on it does it
    > fail
    > as well?
    >
    >
    > "Max" wrote:
    >
    >> Hi There!
    >>
    >> I'm having a mysterious error right after I login using Forms
    >> Authentication
    >> in my ASP.NET app. Below is the error...
    >>
    >> Exception Details: System.NullReferenceException: Object reference not
    >> set
    >> to an instance of an object.
    >>
    >> The exception throws at the code that tries to set a property (String
    >> data
    >> type) at my Menu user control.
    >>
    >> When I refresh the page, the page render successfully without any
    >> exceptions! Why?? My conclusion is that there are no exceptions in the
    >> first
    >> place. I can't think why ASP.NET throws the exception when I access the
    >> page
    >> for first time but not the second time! This exception is totally
    >> unpredictable and unreasonable!
    >>
    >> Plz help!!!
    >>
    >> My SYS specs are...
    >> - ASP.NET 1.1
    >> - Windows XP (This error also occurs on Windows 2000 and Windows Server
    >> 2003
    >> as well)
    >>
    >> Thank you all in advance.
    >>
    >> Max
    >>
    >>
    >>

    Max Guest

  9. #9

    Default Re: Mysterious Error: Object reference not set to an instance of an object

    Hi Kevin,

    Thanks for the reply.

    What I have is an ASPX page, with one Header.ascx control which accepts
    comma delimited menu items (such as Menu1,Menu2,Menu3). For testing
    purposes, I've created a blank ASPX page with only header ASCX control on it
    and on Page_Load, I set the menu items "Menu1,Menu2,Menu3".

    I refresh the page rapidly. Every two or three refresh, I get the "Object
    reference not set to an instance of an object" at the point where I tried to
    assign the menu item values. So I commented out that line and I tried to
    access MenuBarColor property of the header control. The SAME error
    produces!!! So I concluded that my Header control is not instantiated for
    some reason when I do rapid refresh.

    Is this normal for ASP.NET to produce this error when rapidly refreshed or
    what I'm doing wrong?

    max

    "Kevin Spencer" <kevinDIESPAMMERSDIEtakempis.com> wrote in message
    news:erLB6wZ8EHA.3908TK2MSFTNGP12.phx.gbl...
    > The NullReferenceException indicates that you are referencing an object in
    > a line of code, and that the object is null, or Nothing. It is not
    > instantiated. If you post the line of code which throws the exception, I
    > can tell you all of the object references in the line of code which may or
    > may not be null. After that, it will be up to you to determine which, and
    > why.
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > .Net Developer
    > Neither a follower nor a lender be.
    >
    > "Max" <zeromaxdot.com.com> wrote in message
    > news:Ox7ss%23U8EHA.3236TK2MSFTNGP15.phx.gbl...
    >> Hi There!
    >>
    >> I'm having a mysterious error right after I login using Forms
    >> Authentication in my ASP.NET app. Below is the error...
    >>
    >> Exception Details: System.NullReferenceException: Object reference not
    >> set to an instance of an object.
    >>
    >> The exception throws at the code that tries to set a property (String
    >> data type) at my Menu user control.
    >>
    >> When I refresh the page, the page render successfully without any
    >> exceptions! Why?? My conclusion is that there are no exceptions in the
    >> first place. I can't think why ASP.NET throws the exception when I access
    >> the page for first time but not the second time! This exception is
    >> totally unpredictable and unreasonable!
    >>
    >> Plz help!!!
    >>
    >> My SYS specs are...
    >> - ASP.NET 1.1
    >> - Windows XP (This error also occurs on Windows 2000 and Windows Server
    >> 2003 as well)
    >>
    >> Thank you all in advance.
    >>
    >> Max
    >>
    >
    >

    Max Guest

  10. #10

    Default Re: Mysterious Error: Object reference not set to an instance of a

    Hi Yatendra,

    My page does not utilize the Page.IsPostBack.

    max

    "Yatendra Khandelwal" <yatendra.khandelwalishisystems.com.(donotspam) >
    wrote in message news:148939D8-7857-4F27-9768-01E07CF17C32microsoft.com...
    >I think Navajo is right... the problem lies in 'if(!Page.IsPostBack)' of
    > Page_Load().
    > ...... whenever any control does a postback it goes through the
    > Page_Load() again. So the code that we donot want to run on every postback
    > we
    > give in 'if(!Page.IsPostBack) {...}'. The code inside this loop only
    > executes
    > when the page is loaded for the first time or an equivalent situation when
    > we
    > refresh the page. I think thts where your problem lies Max. I think you
    > are
    > initialising the menu control inside this if loop and somehow somewhere
    > your
    > menu control loses its value, b4 coming back to page_load() on some
    > postback.
    > And when it comes there its does not initialise the menu control as this
    > code
    > is inside the if loop and it goes inside the if loop only when its not a
    > postback.
    > If you are initialising menu control in Page_Load() inside the
    > 'if(!Page.IsPostBack)' try doing it outside this loop.
    > I am not very sure of your problem but if what I think your problem is is
    > correct then I guess this should work.
    >
    >
    > "Kevin Spencer" wrote:
    >
    >> Are you the same person who asked the original question? If so, you need
    >> to
    >> post the offending line of code. If not, what the heck are you talking
    >> about?
    >>
    >> --
    >> HTH,
    >>
    >> Kevin Spencer
    >> Microsoft MVP
    >> ..Net Developer
    >> Neither a follower nor a lender be.
    >>
    >> "Navajo Boy" <navajonikeboyrocketmail.com> wrote in message
    >> news:1104765844.492129.251700c13g2000cwb.googlegr oups.com...
    >> > Inside the Page_Load function on the page i believe there is a
    >> > if(!Page.IsPostBack)
    >> > that is loading the Object. Look there.
    >> >
    >> >
    >> >
    >> > Kevin Spencer wrote:
    >> >> The NullReferenceException indicates that you are referencing an
    >> > object in a
    >> >> line of code, and that the object is null, or Nothing. It is not
    >> >> instantiated. If you post the line of code which throws the
    >> > exception, I can
    >> >> tell you all of the object references in the line of code which may
    >> > or may
    >> >> not be null. After that, it will be up to you to determine which, and
    >> > why.
    >> >>
    >> >> --
    >> >> HTH,
    >> >>
    >> >> Kevin Spencer
    >> >> Microsoft MVP
    >> >> .Net Developer
    >> >> Neither a follower nor a lender be.
    >> >>
    >> >> "Max" <zeromaxdot.com.com> wrote in message
    >> >> news:Ox7ss%23U8EHA.3236TK2MSFTNGP15.phx.gbl...
    >> >> > Hi There!
    >> >> >
    >> >> > I'm having a mysterious error right after I login using Forms
    >> >> > Authentication in my ASP.NET app. Below is the error...
    >> >> >
    >> >> > Exception Details: System.NullReferenceException: Object reference
    >> > not set
    >> >> > to an instance of an object.
    >> >> >
    >> >> > The exception throws at the code that tries to set a property
    >> > (String data
    >> >> > type) at my Menu user control.
    >> >> >
    >> >> > When I refresh the page, the page render successfully without any
    >> >> > exceptions! Why?? My conclusion is that there are no exceptions in
    >> > the
    >> >> > first place. I can't think why ASP.NET throws the exception when I
    >> > access
    >> >> > the page for first time but not the second time! This exception is
    >> > totally
    >> >> > unpredictable and unreasonable!
    >> >> >
    >> >> > Plz help!!!
    >> >> >
    >> >> > My SYS specs are...
    >> >> > - ASP.NET 1.1
    >> >> > - Windows XP (This error also occurs on Windows 2000 and Windows
    >> > Server
    >> >> > 2003 as well)
    >> >> >
    >> >> > Thank you all in advance.
    >> >> >
    >> >> > Max
    >> >> >
    >> >
    >>
    >>
    >>

    Max Guest

  11. #11

    Default Re: Mysterious Error: Object reference not set to an instance of a

    What on earth makes you think that that particular line of code is in every
    ASP.Net Page class?

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Neither a follower nor a lender be.

    "Yatendra Khandelwal" <yatendra.khandelwalishisystems.com.(donotspam) >
    wrote in message news:148939D8-7857-4F27-9768-01E07CF17C32microsoft.com...
    >I think Navajo is right... the problem lies in 'if(!Page.IsPostBack)' of
    > Page_Load().
    > ...... whenever any control does a postback it goes through the
    > Page_Load() again. So the code that we donot want to run on every postback
    > we
    > give in 'if(!Page.IsPostBack) {...}'. The code inside this loop only
    > executes
    > when the page is loaded for the first time or an equivalent situation when
    > we
    > refresh the page. I think thts where your problem lies Max. I think you
    > are
    > initialising the menu control inside this if loop and somehow somewhere
    > your
    > menu control loses its value, b4 coming back to page_load() on some
    > postback.
    > And when it comes there its does not initialise the menu control as this
    > code
    > is inside the if loop and it goes inside the if loop only when its not a
    > postback.
    > If you are initialising menu control in Page_Load() inside the
    > 'if(!Page.IsPostBack)' try doing it outside this loop.
    > I am not very sure of your problem but if what I think your problem is is
    > correct then I guess this should work.
    >
    >
    > "Kevin Spencer" wrote:
    >
    >> Are you the same person who asked the original question? If so, you need
    >> to
    >> post the offending line of code. If not, what the heck are you talking
    >> about?
    >>
    >> --
    >> HTH,
    >>
    >> Kevin Spencer
    >> Microsoft MVP
    >> ..Net Developer
    >> Neither a follower nor a lender be.
    >>
    >> "Navajo Boy" <navajonikeboyrocketmail.com> wrote in message
    >> news:1104765844.492129.251700c13g2000cwb.googlegr oups.com...
    >> > Inside the Page_Load function on the page i believe there is a
    >> > if(!Page.IsPostBack)
    >> > that is loading the Object. Look there.
    >> >
    >> >
    >> >
    >> > Kevin Spencer wrote:
    >> >> The NullReferenceException indicates that you are referencing an
    >> > object in a
    >> >> line of code, and that the object is null, or Nothing. It is not
    >> >> instantiated. If you post the line of code which throws the
    >> > exception, I can
    >> >> tell you all of the object references in the line of code which may
    >> > or may
    >> >> not be null. After that, it will be up to you to determine which, and
    >> > why.
    >> >>
    >> >> --
    >> >> HTH,
    >> >>
    >> >> Kevin Spencer
    >> >> Microsoft MVP
    >> >> .Net Developer
    >> >> Neither a follower nor a lender be.
    >> >>
    >> >> "Max" <zeromaxdot.com.com> wrote in message
    >> >> news:Ox7ss%23U8EHA.3236TK2MSFTNGP15.phx.gbl...
    >> >> > Hi There!
    >> >> >
    >> >> > I'm having a mysterious error right after I login using Forms
    >> >> > Authentication in my ASP.NET app. Below is the error...
    >> >> >
    >> >> > Exception Details: System.NullReferenceException: Object reference
    >> > not set
    >> >> > to an instance of an object.
    >> >> >
    >> >> > The exception throws at the code that tries to set a property
    >> > (String data
    >> >> > type) at my Menu user control.
    >> >> >
    >> >> > When I refresh the page, the page render successfully without any
    >> >> > exceptions! Why?? My conclusion is that there are no exceptions in
    >> > the
    >> >> > first place. I can't think why ASP.NET throws the exception when I
    >> > access
    >> >> > the page for first time but not the second time! This exception is
    >> > totally
    >> >> > unpredictable and unreasonable!
    >> >> >
    >> >> > Plz help!!!
    >> >> >
    >> >> > My SYS specs are...
    >> >> > - ASP.NET 1.1
    >> >> > - Windows XP (This error also occurs on Windows 2000 and Windows
    >> > Server
    >> >> > 2003 as well)
    >> >> >
    >> >> > Thank you all in advance.
    >> >> >
    >> >> > Max
    >> >> >
    >> >
    >>
    >>
    >>

    Kevin Spencer Guest

  12. #12

    Default Re: Mysterious Error: Object reference not set to an instance of a

    So, Max, getting back to my question...

    Would you please post the offending line of code?

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Neither a follower nor a lender be.

    "Max" <zeromaxdot.com.com> wrote in message
    news:%23fAjhud8EHA.2900TK2MSFTNGP09.phx.gbl...
    > Hi Yatendra,
    >
    > My page does not utilize the Page.IsPostBack.
    >
    > max
    >
    > "Yatendra Khandelwal" <yatendra.khandelwalishisystems.com.(donotspam) >
    > wrote in message
    > news:148939D8-7857-4F27-9768-01E07CF17C32microsoft.com...
    >>I think Navajo is right... the problem lies in 'if(!Page.IsPostBack)' of
    >> Page_Load().
    >> ...... whenever any control does a postback it goes through the
    >> Page_Load() again. So the code that we donot want to run on every
    >> postback we
    >> give in 'if(!Page.IsPostBack) {...}'. The code inside this loop only
    >> executes
    >> when the page is loaded for the first time or an equivalent situation
    >> when we
    >> refresh the page. I think thts where your problem lies Max. I think you
    >> are
    >> initialising the menu control inside this if loop and somehow somewhere
    >> your
    >> menu control loses its value, b4 coming back to page_load() on some
    >> postback.
    >> And when it comes there its does not initialise the menu control as this
    >> code
    >> is inside the if loop and it goes inside the if loop only when its not a
    >> postback.
    >> If you are initialising menu control in Page_Load() inside the
    >> 'if(!Page.IsPostBack)' try doing it outside this loop.
    >> I am not very sure of your problem but if what I think your problem is is
    >> correct then I guess this should work.
    >>
    >>
    >> "Kevin Spencer" wrote:
    >>
    >>> Are you the same person who asked the original question? If so, you need
    >>> to
    >>> post the offending line of code. If not, what the heck are you talking
    >>> about?
    >>>
    >>> --
    >>> HTH,
    >>>
    >>> Kevin Spencer
    >>> Microsoft MVP
    >>> ..Net Developer
    >>> Neither a follower nor a lender be.
    >>>
    >>> "Navajo Boy" <navajonikeboyrocketmail.com> wrote in message
    >>> news:1104765844.492129.251700c13g2000cwb.googlegr oups.com...
    >>> > Inside the Page_Load function on the page i believe there is a
    >>> > if(!Page.IsPostBack)
    >>> > that is loading the Object. Look there.
    >>> >
    >>> >
    >>> >
    >>> > Kevin Spencer wrote:
    >>> >> The NullReferenceException indicates that you are referencing an
    >>> > object in a
    >>> >> line of code, and that the object is null, or Nothing. It is not
    >>> >> instantiated. If you post the line of code which throws the
    >>> > exception, I can
    >>> >> tell you all of the object references in the line of code which may
    >>> > or may
    >>> >> not be null. After that, it will be up to you to determine which, and
    >>> > why.
    >>> >>
    >>> >> --
    >>> >> HTH,
    >>> >>
    >>> >> Kevin Spencer
    >>> >> Microsoft MVP
    >>> >> .Net Developer
    >>> >> Neither a follower nor a lender be.
    >>> >>
    >>> >> "Max" <zeromaxdot.com.com> wrote in message
    >>> >> news:Ox7ss%23U8EHA.3236TK2MSFTNGP15.phx.gbl...
    >>> >> > Hi There!
    >>> >> >
    >>> >> > I'm having a mysterious error right after I login using Forms
    >>> >> > Authentication in my ASP.NET app. Below is the error...
    >>> >> >
    >>> >> > Exception Details: System.NullReferenceException: Object reference
    >>> > not set
    >>> >> > to an instance of an object.
    >>> >> >
    >>> >> > The exception throws at the code that tries to set a property
    >>> > (String data
    >>> >> > type) at my Menu user control.
    >>> >> >
    >>> >> > When I refresh the page, the page render successfully without any
    >>> >> > exceptions! Why?? My conclusion is that there are no exceptions in
    >>> > the
    >>> >> > first place. I can't think why ASP.NET throws the exception when I
    >>> > access
    >>> >> > the page for first time but not the second time! This exception is
    >>> > totally
    >>> >> > unpredictable and unreasonable!
    >>> >> >
    >>> >> > Plz help!!!
    >>> >> >
    >>> >> > My SYS specs are...
    >>> >> > - ASP.NET 1.1
    >>> >> > - Windows XP (This error also occurs on Windows 2000 and Windows
    >>> > Server
    >>> >> > 2003 as well)
    >>> >> >
    >>> >> > Thank you all in advance.
    >>> >> >
    >>> >> > Max
    >>> >> >
    >>> >
    >>>
    >>>
    >>>
    >
    >

    Kevin Spencer Guest

  13. #13

    Default Re: Mysterious Error: Object reference not set to an instance of an object

    It would help if you post the offending line of code. No, it is not normal
    for you to get that exception, unless there is a bug in your code.

    BTW, tip: Stick to one thread. Don't start new ones. Unlike Hansel and
    Gretel, you're posts don't leave bread crumbs!

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    Neither a follower nor a lender be.

    "Max" <zeromaxdot.com.com> wrote in message
    news:ORk0ltd8EHA.3840tk2msftngp13.phx.gbl...
    > Hi Kevin,
    >
    > Thanks for the reply.
    >
    > What I have is an ASPX page, with one Header.ascx control which accepts
    > comma delimited menu items (such as Menu1,Menu2,Menu3). For testing
    > purposes, I've created a blank ASPX page with only header ASCX control on
    > it and on Page_Load, I set the menu items "Menu1,Menu2,Menu3".
    >
    > I refresh the page rapidly. Every two or three refresh, I get the "Object
    > reference not set to an instance of an object" at the point where I tried
    > to assign the menu item values. So I commented out that line and I tried
    > to access MenuBarColor property of the header control. The SAME error
    > produces!!! So I concluded that my Header control is not instantiated for
    > some reason when I do rapid refresh.
    >
    > Is this normal for ASP.NET to produce this error when rapidly refreshed or
    > what I'm doing wrong?
    >
    > max
    >
    > "Kevin Spencer" <kevinDIESPAMMERSDIEtakempis.com> wrote in message
    > news:erLB6wZ8EHA.3908TK2MSFTNGP12.phx.gbl...
    >> The NullReferenceException indicates that you are referencing an object
    >> in a line of code, and that the object is null, or Nothing. It is not
    >> instantiated. If you post the line of code which throws the exception, I
    >> can tell you all of the object references in the line of code which may
    >> or may not be null. After that, it will be up to you to determine which,
    >> and why.
    >>
    >> --
    >> HTH,
    >>
    >> Kevin Spencer
    >> Microsoft MVP
    >> .Net Developer
    >> Neither a follower nor a lender be.
    >>
    >> "Max" <zeromaxdot.com.com> wrote in message
    >> news:Ox7ss%23U8EHA.3236TK2MSFTNGP15.phx.gbl...
    >>> Hi There!
    >>>
    >>> I'm having a mysterious error right after I login using Forms
    >>> Authentication in my ASP.NET app. Below is the error...
    >>>
    >>> Exception Details: System.NullReferenceException: Object reference not
    >>> set to an instance of an object.
    >>>
    >>> The exception throws at the code that tries to set a property (String
    >>> data type) at my Menu user control.
    >>>
    >>> When I refresh the page, the page render successfully without any
    >>> exceptions! Why?? My conclusion is that there are no exceptions in the
    >>> first place. I can't think why ASP.NET throws the exception when I
    >>> access the page for first time but not the second time! This exception
    >>> is totally unpredictable and unreasonable!
    >>>
    >>> Plz help!!!
    >>>
    >>> My SYS specs are...
    >>> - ASP.NET 1.1
    >>> - Windows XP (This error also occurs on Windows 2000 and Windows Server
    >>> 2003 as well)
    >>>
    >>> Thank you all in advance.
    >>>
    >>> Max
    >>>
    >>
    >>
    >
    >

    Kevin Spencer Guest

  14. #14

    Default Re: Mysterious Error: Object reference not set to an instance of an object

    Max,

    I am going to join Kevin in his plea to post your offending code. It is
    time-consuming, frustrating and sometimes impossible to debug an error from
    behind a curtain. From the symptoms, it seems obvious that you are doing
    something wrong in the rendering or composition of your control, but unless
    we see the code, it is hard to point out where.

    :DG<


    "Max" <zeromaxdot.com.com> wrote in message
    news:ORk0ltd8EHA.3840tk2msftngp13.phx.gbl...
    > Hi Kevin,
    >
    > Thanks for the reply.
    >
    > What I have is an ASPX page, with one Header.ascx control which accepts
    > comma delimited menu items (such as Menu1,Menu2,Menu3). For testing
    > purposes, I've created a blank ASPX page with only header ASCX control on
    > it and on Page_Load, I set the menu items "Menu1,Menu2,Menu3".
    >
    > I refresh the page rapidly. Every two or three refresh, I get the "Object
    > reference not set to an instance of an object" at the point where I tried
    > to assign the menu item values. So I commented out that line and I tried
    > to access MenuBarColor property of the header control. The SAME error
    > produces!!! So I concluded that my Header control is not instantiated for
    > some reason when I do rapid refresh.
    >
    > Is this normal for ASP.NET to produce this error when rapidly refreshed or
    > what I'm doing wrong?
    >
    > max
    >
    > "Kevin Spencer" <kevinDIESPAMMERSDIEtakempis.com> wrote in message
    > news:erLB6wZ8EHA.3908TK2MSFTNGP12.phx.gbl...
    >> The NullReferenceException indicates that you are referencing an object
    >> in a line of code, and that the object is null, or Nothing. It is not
    >> instantiated. If you post the line of code which throws the exception, I
    >> can tell you all of the object references in the line of code which may
    >> or may not be null. After that, it will be up to you to determine which,
    >> and why.
    >>
    >> --
    >> HTH,
    >>
    >> Kevin Spencer
    >> Microsoft MVP
    >> .Net Developer
    >> Neither a follower nor a lender be.
    >>
    >> "Max" <zeromaxdot.com.com> wrote in message
    >> news:Ox7ss%23U8EHA.3236TK2MSFTNGP15.phx.gbl...
    >>> Hi There!
    >>>
    >>> I'm having a mysterious error right after I login using Forms
    >>> Authentication in my ASP.NET app. Below is the error...
    >>>
    >>> Exception Details: System.NullReferenceException: Object reference not
    >>> set to an instance of an object.
    >>>
    >>> The exception throws at the code that tries to set a property (String
    >>> data type) at my Menu user control.
    >>>
    >>> When I refresh the page, the page render successfully without any
    >>> exceptions! Why?? My conclusion is that there are no exceptions in the
    >>> first place. I can't think why ASP.NET throws the exception when I
    >>> access the page for first time but not the second time! This exception
    >>> is totally unpredictable and unreasonable!
    >>>
    >>> Plz help!!!
    >>>
    >>> My SYS specs are...
    >>> - ASP.NET 1.1
    >>> - Windows XP (This error also occurs on Windows 2000 and Windows Server
    >>> 2003 as well)
    >>>
    >>> Thank you all in advance.
    >>>
    >>> Max
    >>>
    >>
    >>
    >
    >

    Dimitri Glazkov Guest

Similar Threads

  1. Replies: 2
    Last Post: June 6th, 04:02 PM
  2. Custom Control Problem :: Object reference not set to an instance of an object
    By David Bowey in forum ASP.NET Building Controls
    Replies: 1
    Last Post: March 16th, 10:33 PM
  3. Replies: 0
    Last Post: March 7th, 11:28 PM
  4. Replies: 0
    Last Post: July 25th, 10:42 AM
  5. Replies: 2
    Last Post: July 9th, 02:49 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139