Access asp content from a Popup Window
<p>I want to access a asp TreeView from a Popup window. I made it public, so I can have access.
Code in Chile or Popup Page,</p>

<pre><code>SomeWebPage FlViewPage = new SomeWebPage(); 
lblMessage.Text = FlViewPage.TreeView1.Nodes.Count.ToString();
</code></pre>

<p>The problem is that when I run the WebSite I got an error: </p>

<pre><code>Object reference not set to an instance of an object.
</code></pre>

<p>WebPage (From which the Popup is called) Code the Tree is populated dynamically,</p>

<pre><code>    &lt;%@ Page Title="Folder View" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="FolderView.aspx.cs" Inherits="SwimWebFile.FolderView" %&gt;
&lt;div id="content"&gt; &lt;div class="post"&gt;
&lt;h1 class="title"&gt; &lt;asp:Label ID="lblTitle" runat="server" Text="Documents"&gt;&lt;/asp:Label&gt;&lt;/h1&gt;
    &lt;div class="entry" &gt;
     &lt;!-- Center the pop window in the middle --&gt;
        &lt;script type="text/javascript"&gt;
            function PopupCenter(pageURL, title, w, h) {
                var left = (screen.width / 2) - (w / 2);
                var top = (screen.height / 2) - (h / 2);
                var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
            } 
        &lt;/script&gt;
        &lt;a href="javascript:void(0);" onclick="PopupCenter('NewFolderPopup.aspx', 'Add Document',340,185);"&gt;Click Here for Upload&lt;/a&gt;
        &lt;font size="4"&gt;
        &lt;asp:TreeView ID="TreeViewDocuments" runat="server" ExpandDepth="0" 
            ImageSet="Simple" Visible="False" onprerender="TreeView_PreRender"&gt;
            &lt;HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" /&gt;
            &lt;LeafNodeStyle NodeSpacing="10px" /&gt;
            &lt;Nodes&gt;
                &lt;asp:TreeNode Text="System" Value="Systems" Expanded="False" 
                    SelectAction="Expand"&gt;
                &lt;/asp:TreeNode&gt;
                &lt;asp:TreeNode Text="Document" Value="Documents" Expanded="False" 
                    SelectAction="Expand"&gt;
                &lt;/asp:TreeNode&gt;
            &lt;/Nodes&gt;
            &lt;NodeStyle Font-Names="Tahoma" Font-Size="Medium" ForeColor="Black" 
                HorizontalPadding="0px" NodeSpacing="7px" VerticalPadding="0px" /&gt;
            &lt;ParentNodeStyle Font-Bold="False" /&gt;
            &lt;SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" 
                HorizontalPadding="0px" VerticalPadding="0px" /&gt;
        &lt;/asp:TreeView&gt;
            &lt;asp:Button ID="btnNewFolder" runat="server" Text="New Folder" 
            onclick="btnNewFolder_Click" UseSubmitBehavior="False"/&gt;
            &lt;asp:Button ID="btnRenameFolder" runat="server" Text="Rename Folder" /&gt;
            &lt;asp:Button ID="btnDeleteFolder" runat="server" Text="Delete Folder" /&gt;
   &lt;/font&gt;&lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>Code behind,</p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
    {
            if (!HttpContext.Current.User.Identity.IsAuthenticated) {
                TreeViewDocuments.Visible = false;
                lblTitle.Text = "You need to be logged in.";
            }
            else
                TreeViewDocuments.Visible = true;
    }
    protected void TreeView_PreRender(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
           AddNewNode();
        }
    }
    // Some Code to pop 
     protected void AddNewNode()
     {
      ...
     }
    .
    .
    .
    protected void btnNewFolder_Click(object sender, EventArgs e)
    {
Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "", "targetWin = window.open('NewFolderPopup.aspx', 'Add Folder', 'toolbar=0, location=0, directories=0, status=0, resizable= 0, menubar=0, copyhistory=no, width=460, height=150');  targetWin.moveTo((screen.height / 2) - (150/ 2), (screen.width / 2) - (460 / 2));", true);
    }
</code></pre>

<p>Error,</p>

<pre><code>    Server Error in '/' Application.

Object reference not set to an instance of an object.

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: 

Line 56:             FolderView FlViewPage = new FolderView();
Line 57:             lblMessage.Text = FlViewPage.TreeViewDocuments.Nodes.Count.ToString();

Stack Trace: 

[NullReferenceException: Object reference not set to an instance of an object.]
   SwimWebFile.NewFolderPopup.btnCreate_Click(Object sender, EventArgs e) in C:\Users\...\NewFolderPopup.aspx.cs:57
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
</code></pre>
