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
是啊,令人困惑,因爲TreeView已經填充在SomeWebPage中,所以我不知道爲什麼不傳遞它的參數或節點。 – SpcCode 2012-02-21 00:11:36
你可以發佈什麼somewebpage看起來盧克? – 2012-02-21 01:03:08
已添加代碼。彈出窗口在從FolderView.aspx調用btnNewFolder時打開。我想讓TreeView節點到這個彈出窗口。 – SpcCode 2012-02-21 01:15:38