2012-02-20 137 views
0

我想从弹出窗口访问asp树视图。我公开了,所以我可以访问。 代码在智利或弹出页面,从弹出窗口访问asp内容

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 

回答

0

有很多,可能是空我会挂钩一个调试器,看看会是空的。此时我的猜测是Treeview1或FlViewPage,但我可能没有完整的图片

+0

是啊,令人困惑,因为TreeView已经填充在SomeWebPage中,所以我不知道为什么不传递它的参数或节点。 – SpcCode 2012-02-21 00:11:36

+0

你可以发布什么somewebpage看起来卢克? – 2012-02-21 01:03:08

+0

已添加代码。弹出窗口在从FolderView.aspx调用btnNewFolder时打开。我想让TreeView节点到这个弹出窗口。 – SpcCode 2012-02-21 01:15:38

0

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

感谢您的建议!