Sharing: A bug and fix for the Microsoft IE WebControls TreeView

Source: Internet
Author: User
Tags bind empty join
Treeview|web
First, thank Shi for pointing out how I can reuse the TreeView, the Microsoft IE WebControl. For more information, see http://community.csdn.net/Expert/TopicView.asp?id=3365114

IE WebControl can be used in HTML files alone or in Web form. NET programs;
For the latter, the use of the program can be added to the node, can also be bound;
For the latter, when binding, you can help set an XML-formatted string, or bind an XML file, as long as you assign a value to the TreeNodeSrc property of the TreeView control;
For the latter, there are two possibilities, one that is bound to an XML file that already exists on the hard disk, or that the TREENODESRC value is set to ".../foo.xml", and the other is to create an ASPX page that dynamically produces an XML-formatted output that is bound to this page.
For the latter, an error is generated.

The reason is that the TreeView control actually has two places to bind, or to parse a data source to produce a tree structure, one in the server Side, and one in the browser Side. In the process of render the TreeView control, if you find that TREENODESRC is an address, it will attempt to read the contents of this address and then parse and explicitly write to the output of the Web page, where an error is generated.

My solution is to define an extended attribute Treenodesrca, which is not parsed on the server side, but is written to browser side, and then the TreeView's HTC reads the contents of the Treenodesrca-pointing URL and parses it.

The specific steps are as follows:

First, in the TreeView of the source program Treeview.cs file

public class Treeview:basepostbackcontrol

Part of the section to join such a


<summary>
URL of the XML file to import as the TreeNode content of the tree, Browser Side Binding
</summary>
[
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 function is to define a property called Treenodesrca.

Second, in the TreeView source program Treeview.cs File

protected override void Renderuplevelpath (HtmlTextWriter output)

method to add such a paragraph

if (Treenodesrca!= String.Empty)
Output. AddAttribute ("Treenodesrca", Treenodesrca);

Its role is to write to the output of a Web page if the Treenodesrca attribute is non-null.

Compile the build DLL file and reference

Four, in the TreeView script file treeview.htc the corresponding location to add:

<public:property name= "Treenodesrca" id= "_tvproptreenodesrca" get= "Gettreenodesrca" PUT= "SetTreeNodeSrcA"/>

var prop_treenodesrca = null;

function Gettreenodesrca ()
{
return Prop_treenodesrca;
}

function Settreenodesrca (value)
{
if (Prop_treenodesrca!= value)
{
Prop_treenodesrca = value;
}
}

This is the description that defines an HTC attribute, sets the variable to store, and sets the way to read and write it.

Five, in the TreeView script file Treeview.htc function Oncontentready (), in the
if (treenodesrc!= null)
Before, join:
if (Treenodesrca!= null)
TREENODESRC = Treenodesrca;
This guarantees that when creating, if the extended attribute is Treenodesrca, it will be used to fill the treenodesrc, then browser will read the data source and parse, bind.

"Athossmth Original, reprint please specify, thank you"



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.