Sharing: a bug and correction of Microsoft IE WebControls TreeView

xiaoxiao2021-03-06  39

First of all, I would like to think about how I use TreeView this Microsoft IE WebControl. See http://community.9cbs.net/expert/topicview.asp?id=3365114

IE WebControl can be used separately in the HTML file, or it can also be used for .NET programs for web form; A string of an XML format, or you can bind an XML file, just assign a value to the TreeView control; for the latter, there are two possibilities, one is bound to an XML file that already exists on the hard disk, or The value of Treenodesrc is set to "..... / foo.xml", and the other is to create an ASPX page dynamically generated an output of XML format, bind to this page. For the latter, an error will occur.

The reason is that the TreeView control actually has two places that can be bound, or that parsing the data source produces a structure, one is in Server Side, one is in Browser Side. During the TreeView control render, if the TreenODesRC is found, it will try to read the content of this address, then resolve, and explicitly write into the output of the web page, there is an error here.

My solution is to define an extended property TreenOdesrca, which is not parsed in the Server side, but is unwritten to the Browser Side, then the TreeView's HTC reads the contents of the URL pointing to Treenodesrca and parses.

Specific steps are as follows:

First, in the TreeView source program TreeView.cs file

Public Class TreeView: BasePostbackControl

Part of the part to join this

///

/// URL of the XML File to Import As the Treenode Content of the Tree, Browser Side Binding /// [Category ("Data"), DefaultValue (""), PersistenceMode PersistenceMode.Attribute), ResDescription ( "TreeNodeSrcA"),] public string TreeNodeSrcA {get {object str = ViewState [ "TreeNodeSrcA"]; return ((str == null) String.Empty:? (string) str);} set {ViewState ["Treenodesrca"] = value;}}

Its role is to define a property called TreenODesrca.

Second, in the TreeView source program TreeView.cs file

Protected Override Void RenderuplevelPath (HTMLTextWriter Output)

Join this paragraph

IF (Treenodesrca! = String.empty) Output.addattribute ("Treenodesrca", TreenoDesrca;

Its role is that if the TreenODesrca property is not empty, it is written to the output of the web page. Third, compilation to generate a DLL file and reference

Fourth, the corresponding position of TreeView.htc at TreeView is added:

Var prop_treenodesrca = NULL;

Function gettreenodesrca () {return prop_treenodesrca;}

Function settreenodesrca (value) {if (Prop_treenodesrca! = value) {prop_treenodesrca = value;}}

This means that the properties in an HTC are defined, set the variable to store, and set the method of reading it.

5. In the Function OnContentReady () of TreeView.htc, before IF (Treenodesrc! = Null), add: if (Treenodesrca! = Null) Treenodesrc = Treenodesrca; this guarantees that if the creation is created, if expanded Attribute Treenodesrca is non-empty, it will use it to fill TreenODesrc, and Browser will go to read the data source and resolve, bind.

[Athossmth original, reprint, please specify, thank you]

转载请注明原文地址:https://www.9cbs.com/read-53483.html

New Post(0)