R
Rich Fowler
I'm dynamically binding an XmlDataSource to an xml file in the Page_Load
event. This XmlDataSource control is the DataSourceID for a TreeView
control. I'm receiving a null reference error prior to entering the
Page_Load event when selecting a tree text value.
Page_Load code snippet:
cSchemaXML.DataFile = @"D:\Schemas\2008\Schema_Tree.xml";
Note: The file path above will be calculated once I get it working. This is
for testing only. The code is not in a !this.IsPostBack conditional.
Aspx page snippet:
<asp:TreeView ID="cSchemaTree" runat="server" DataSourceID="cSchemaXML"
ExpandDepth="1">
</asp:TreeView>
<asp:XmlDataSource ID="cSchemaXML" runat="server"></asp:XmlDataSource>
When I click on the tree node (not the Expand icon) for the select
processing, a null reference error (see below) is displayed.
The only way I can get this to work without a the error is to disable client
side code:
EnableClientScript="False"
I prefer not to suffer the flashing and time required during postbacks. I'm
simply trying to display the xml element tree structure. The xml being
displayed is nested elements, each containing one attribute. If I set the
DataFile in the XmlDataSource control directly, everything works fine. Do I
need to set DataFile someplace other than in the Page_Load event? Some other
solution?
Note: If I click a tree node that is part of the initial display (based on
the ExpandDepth setting) I do not get the error until I expand the tree and
then click the node (or one of the expanded nodes). This may indicate some
variance between the viewstate and the returned tree structure (only a
guess).
Sample XML - the actual xml is much more complex and nested much deeper, but
this gives the idea.
<Company FullPath="Company">
<Name FullPath="Company/Name"/>
<Address FullPath="Company/Address">
<USAddress FullPath="Company/Address/USAddress">
<Street FullPath="Company/Address/USAddress/Street" />
<City FullPath="Company/Address/USAddress/City"/>
<State FullPath="Company/Address/USAddress/State" />
<ZipCode FullPath="Company/Address/USAddress/ZipCode" />
</USAddress>
<ForeignAddress FullPath="Company/Address/ForeignAddress" >
<Street FullPath="Company/Address/USAddress/Street" />
<City FullPath="Company/Address/USAddress/City"/>
<StateOrProvince FullPath="Company/Address/USAddress/StateOrProvince"
/>
<PostalCode FullPath="Company/Address/USAddress/PostalCode" />
<Country FullPath="Company/Address/ForeignAddress/Country" />
</ForeignAddress>
</Address>
</Company>
The error returned when clicking the tree node is:
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:
An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean
preserveWhitespace) +24
System.Xml.XmlDocument.Load(XmlReader reader) +96
System.Web.UI.WebControls.XmlDataSource.PopulateXmlDocument(XmlDocument
document, CacheDependency& dataCacheDependency, CacheDependency&
transformCacheDependency) +305
System.Web.UI.WebControls.XmlDataSource.GetXmlDocument() +154
System.Web.UI.WebControls.XmlHierarchicalDataSourceView.Select() +14
System.Web.UI.WebControls.TreeView.DataBindNode(TreeNode node) +126
System.Web.UI.WebControls.TreeView.PopulateNode(TreeNode node) +27
System.Web.UI.WebControls.TreeView.LoadPostData(String postDataKey,
NameValueCollection postCollection) +1082
System.Web.UI.WebControls.TreeView.System.Web.UI.IPostBackDataHandler.LoadPostData(String
postDataKey, NameValueCollection postCollection) +11
System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean
fBeforeLoad) +661
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1194
Thanks for any help - Rich F.
event. This XmlDataSource control is the DataSourceID for a TreeView
control. I'm receiving a null reference error prior to entering the
Page_Load event when selecting a tree text value.
Page_Load code snippet:
cSchemaXML.DataFile = @"D:\Schemas\2008\Schema_Tree.xml";
Note: The file path above will be calculated once I get it working. This is
for testing only. The code is not in a !this.IsPostBack conditional.
Aspx page snippet:
<asp:TreeView ID="cSchemaTree" runat="server" DataSourceID="cSchemaXML"
ExpandDepth="1">
</asp:TreeView>
<asp:XmlDataSource ID="cSchemaXML" runat="server"></asp:XmlDataSource>
When I click on the tree node (not the Expand icon) for the select
processing, a null reference error (see below) is displayed.
The only way I can get this to work without a the error is to disable client
side code:
EnableClientScript="False"
I prefer not to suffer the flashing and time required during postbacks. I'm
simply trying to display the xml element tree structure. The xml being
displayed is nested elements, each containing one attribute. If I set the
DataFile in the XmlDataSource control directly, everything works fine. Do I
need to set DataFile someplace other than in the Page_Load event? Some other
solution?
Note: If I click a tree node that is part of the initial display (based on
the ExpandDepth setting) I do not get the error until I expand the tree and
then click the node (or one of the expanded nodes). This may indicate some
variance between the viewstate and the returned tree structure (only a
guess).
Sample XML - the actual xml is much more complex and nested much deeper, but
this gives the idea.
<Company FullPath="Company">
<Name FullPath="Company/Name"/>
<Address FullPath="Company/Address">
<USAddress FullPath="Company/Address/USAddress">
<Street FullPath="Company/Address/USAddress/Street" />
<City FullPath="Company/Address/USAddress/City"/>
<State FullPath="Company/Address/USAddress/State" />
<ZipCode FullPath="Company/Address/USAddress/ZipCode" />
</USAddress>
<ForeignAddress FullPath="Company/Address/ForeignAddress" >
<Street FullPath="Company/Address/USAddress/Street" />
<City FullPath="Company/Address/USAddress/City"/>
<StateOrProvince FullPath="Company/Address/USAddress/StateOrProvince"
/>
<PostalCode FullPath="Company/Address/USAddress/PostalCode" />
<Country FullPath="Company/Address/ForeignAddress/Country" />
</ForeignAddress>
</Address>
</Company>
The error returned when clicking the tree node is:
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:
An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean
preserveWhitespace) +24
System.Xml.XmlDocument.Load(XmlReader reader) +96
System.Web.UI.WebControls.XmlDataSource.PopulateXmlDocument(XmlDocument
document, CacheDependency& dataCacheDependency, CacheDependency&
transformCacheDependency) +305
System.Web.UI.WebControls.XmlDataSource.GetXmlDocument() +154
System.Web.UI.WebControls.XmlHierarchicalDataSourceView.Select() +14
System.Web.UI.WebControls.TreeView.DataBindNode(TreeNode node) +126
System.Web.UI.WebControls.TreeView.PopulateNode(TreeNode node) +27
System.Web.UI.WebControls.TreeView.LoadPostData(String postDataKey,
NameValueCollection postCollection) +1082
System.Web.UI.WebControls.TreeView.System.Web.UI.IPostBackDataHandler.LoadPostData(String
postDataKey, NameValueCollection postCollection) +11
System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean
fBeforeLoad) +661
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1194
Thanks for any help - Rich F.