Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Master Page and Session null pointer on page load

Master Page and Session null pointer on page load

Scheduled Pinned Locked Moved ASP.NET
questiondotnetworkspace
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alberto Bar Noy
    wrote on last edited by
    #1

    Hello all, After a fare 3 hour of "banging my head on the wall" (and the internet) here is a question for you. I have a master page (surprise surprise) and in it in the Page_Load I am trying to pull out some variables from the Session. However my Session variable is null What am I doing wrong:confused::confused::confused:? Am I missing some configuration issues or permission issues? Thank you! Alberto

    Alberto Bar-Noy Project Manager http://www.consist.co.il

    D J 2 Replies Last reply
    0
    • A Alberto Bar Noy

      Hello all, After a fare 3 hour of "banging my head on the wall" (and the internet) here is a question for you. I have a master page (surprise surprise) and in it in the Page_Load I am trying to pull out some variables from the Session. However my Session variable is null What am I doing wrong:confused::confused::confused:? Am I missing some configuration issues or permission issues? Thank you! Alberto

      Alberto Bar-Noy Project Manager http://www.consist.co.il

      D Offline
      D Offline
      dekart_roo
      wrote on last edited by
      #2

      Well... if It's in the onload of the master page, that means it will be among the very first lines of code executed in your application. Thus, it will be checking for the session variable, in all likelyhood, before you can get the chance to set it. Before using the session variable in any way, try checking first to see if it's null, or use a try catch block to stave off unhandled exceptions until you can set the session variable.

      J D 2 Replies Last reply
      0
      • A Alberto Bar Noy

        Hello all, After a fare 3 hour of "banging my head on the wall" (and the internet) here is a question for you. I have a master page (surprise surprise) and in it in the Page_Load I am trying to pull out some variables from the Session. However my Session variable is null What am I doing wrong:confused::confused::confused:? Am I missing some configuration issues or permission issues? Thank you! Alberto

        Alberto Bar-Noy Project Manager http://www.consist.co.il

        J Offline
        J Offline
        JacquesDP
        wrote on last edited by
        #3

        I take it that you received a NullReferenceException? I had the same issue, my problem was that the Session("X") did not have a value before I tried to access it.

        No matter how long he who laughs last laughs, he who laughs first has a head start!

        1 Reply Last reply
        0
        • D dekart_roo

          Well... if It's in the onload of the master page, that means it will be among the very first lines of code executed in your application. Thus, it will be checking for the session variable, in all likelyhood, before you can get the chance to set it. Before using the session variable in any way, try checking first to see if it's null, or use a try catch block to stave off unhandled exceptions until you can set the session variable.

          J Offline
          J Offline
          JacquesDP
          wrote on last edited by
          #4

          Where can you set the default values for Session Variables? In asp it used to be in the Global.asa file under Session_OnStart, but where do you do it in asp.net?

          No matter how long he who laughs last laughs, he who laughs first has a head start!

          P 1 Reply Last reply
          0
          • J JacquesDP

            Where can you set the default values for Session Variables? In asp it used to be in the Global.asa file under Session_OnStart, but where do you do it in asp.net?

            No matter how long he who laughs last laughs, he who laughs first has a head start!

            P Offline
            P Offline
            Paddy Boyd
            wrote on last edited by
            #5

            Strangely in a very similarly named method in the global.asax...

            J 1 Reply Last reply
            0
            • P Paddy Boyd

              Strangely in a very similarly named method in the global.asax...

              J Offline
              J Offline
              JacquesDP
              wrote on last edited by
              #6

              Thanks, I was under the impression that the web.config replaced the global.asa

              No matter how long he who laughs last laughs, he who laughs first has a head start!

              1 Reply Last reply
              0
              • D dekart_roo

                Well... if It's in the onload of the master page, that means it will be among the very first lines of code executed in your application. Thus, it will be checking for the session variable, in all likelyhood, before you can get the chance to set it. Before using the session variable in any way, try checking first to see if it's null, or use a try catch block to stave off unhandled exceptions until you can set the session variable.

                D Offline
                D Offline
                doWhileSomething
                wrote on last edited by
                #7

                dekart_roo wrote:

                Well... if It's in the onload of the master page, that means it will be among the very first lines of code executed in your application. Thus, it will be checking for the session variable, in all likelyhood, before you can get the chance to set it.

                This is not really accurate (not trying to offend anyone). If you use a master page (with a content page obviously) the order of events (I might miss one) are as follows. Keys: C = content page M = master page 1) Pre_init (C) 2) Page_init (M) 3) Page_init (C) 4) Page_init_complete (C) 5) Page_load (C) 6) Page_load (M) 7) Page_PreRender (M) Part of the reason for the events taking place like this is it gives you the flexibility of manipulating "something" on the master page based of "something" on the content page. Just thought someone might find this usefull.

                My Personal Site

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups