Why do I get "Object reference not set to an instance of an object." when changing pages in asp.net
<p>I have a master page that set ups some variables that I want to use across the site.. </p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
{
    //Get users name from AD
    str_DomainName = HttpContext.Current.User.Identity.Name;
    str_CurrentLogin = str_DomainName.Substring(5);

    //Display current user information
    DirectorySearcher search = new DirectorySearcher("LDAP://DCHS");
    search.Filter = String.Format("(SAMAccountName={0})", str_CurrentLogin);
    SearchResult result = search.FindOne();
    DirectoryEntry entry = result.GetDirectoryEntry();
    lbl_CurrentUser.Text = result.Properties["givenName"][0].ToString() + ' ' + result.Properties["sn"][0].ToString();

    // Get SID
    IntPtr logonToken = WindowsIdentity.GetCurrent().Token;
    WindowsIdentity windowsId = new WindowsIdentity(logonToken);

    //Set session variabls
    this.CurrentFirstName = result.Properties["givenName"][0].ToString();
    //this.CurrentEmail = result.Properties["mail"][0].ToString();
    //this.CurrentSID = windowsId.User.ToString();
    //this.CurrentUserName = str_CurrentLogin;
    //this.CurrentFullName = lbl_CurrentUser.Text;
    //this.CurrentDomain = str_DomainName;
    this.Session.Add("currentEmail", result.Properties["mail"][0].ToString());
}

public String CurrentFirstName
        {
            get { return (String)ViewState["currentFirstName"]; }
            set { ViewState["currentFirstName"] = value; }
        }
</code></pre>

<p>I then call them in my defalut.aspx page as follows:</p>

<pre><code>protected void Page_PreRender(object sender, EventArgs e)
        {
            //try
            //{
                lbl_FullName.Text = Master.CurrentFullName;
                lbl_SID.Text = Master.CurrentSID;
                testLabel.Text = Master.CurrentEmail;
            //}
            //catch (Exception ex)
            //{ }
        }
</code></pre>

<p>This works fine.. If I however navigate away from the default page, then I get the following error.. </p>

<blockquote>
  <p>Object reference not set to an instance of an object.</p>
</blockquote>

<p>One the <code>lbl_FullName.Text = Master.CurrentFullName;</code> line</p>

<p>If I uncomment the try catch then it works fine, but I don't believe that this is the correct method of avoiding the fault.. </p>

<p>I'm only new to ASP, so be nice..</p>

<p>EDIT:</p>

<p>The variabes are being set in Master.cs as follows.</p>

<pre><code>public String CurrentUserName
        {
            get { return (String)ViewState["currentUserName"]; }
            set { ViewState["currentUserName"] = value; }
        }
</code></pre>
