从弹出窗口访问asp内容

本文关键字:asp 内容 访问 窗口 | 更新日期: 2023-09-27 18:25:25

我想从弹出窗口访问asp TreeView。我把它公开了,这样我就可以访问了。智利代码或弹出页面,

SomeWebPage FlViewPage = new SomeWebPage(); 
lblMessage.Text = FlViewPage.TreeView1.Nodes.Count.ToString();

问题是,当我运行网站时,我得到了一个错误:

Object reference not set to an instance of an object.

网页(从中调用弹出菜单)代码树是动态填充的,

    <%@ Page Title="Folder View" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="FolderView.aspx.cs" Inherits="SwimWebFile.FolderView" %>
<div id="content"> <div class="post">
<h1 class="title"> <asp:Label ID="lblTitle" runat="server" Text="Documents"></asp:Label></h1>
    <div class="entry" >
     <!-- Center the pop window in the middle -->
        <script type="text/javascript">
            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);
            } 
        </script>
        <a href="javascript:void(0);" onclick="PopupCenter('NewFolderPopup.aspx', 'Add Document',340,185);">Click Here for Upload</a>
        <font size="4">
        <asp:TreeView ID="TreeViewDocuments" runat="server" ExpandDepth="0" 
            ImageSet="Simple" Visible="False" onprerender="TreeView_PreRender">
            <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
            <LeafNodeStyle NodeSpacing="10px" />
            <Nodes>
                <asp:TreeNode Text="System" Value="Systems" Expanded="False" 
                    SelectAction="Expand">
                </asp:TreeNode>
                <asp:TreeNode Text="Document" Value="Documents" Expanded="False" 
                    SelectAction="Expand">
                </asp:TreeNode>
            </Nodes>
            <NodeStyle Font-Names="Tahoma" Font-Size="Medium" ForeColor="Black" 
                HorizontalPadding="0px" NodeSpacing="7px" VerticalPadding="0px" />
            <ParentNodeStyle Font-Bold="False" />
            <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" 
                HorizontalPadding="0px" VerticalPadding="0px" />
        </asp:TreeView>
            <asp:Button ID="btnNewFolder" runat="server" Text="New Folder" 
            onclick="btnNewFolder_Click" UseSubmitBehavior="False"/>
            <asp:Button ID="btnRenameFolder" runat="server" Text="Rename Folder" />
            <asp:Button ID="btnDeleteFolder" runat="server" Text="Delete Folder" />
   </font></div>
</div>

代码隐藏,

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);
    }

错误,

    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

从弹出窗口访问asp内容

有很多可能为null,我会将调试器连接到它,看看什么是null。在这一点上,我的猜测是Treeview1或FlViewPage,但我可能没有完整的图片

我找到了解决这个问题的方法。我使用Session方法只接收值,而不是整个TreeView。

谢谢你的建议!