A bug in IE webcontrols Treeview and its correction

Source: Internet
Author: User

First of all, I would like to thank the thought for guiding me How to reuse the Microsoft IE webcontrol Treeview. See the http://community.csdn.net/Expert/TopicView.asp? Id = 3365114

IE webcontrol can be used separately in HTML files or in. Net of web form.Program;

For the latter, you can add or bind nodes through programming;

When binding the latter, you can define an XML string or bind an XML file. You only need to assign a value to the treenodesrc attribute of the Treeview control;

For the latter, there are two possibilities: one is to bind to an XML file that already exists in the hard disk, or set the value of treenodesrc "..... /Foo. the other is to create An ASPX page to dynamically generate an output in XML format and bind it to this page.

For the latter, an error occurs.

The reason is that the Treeview control can be bound in two places, or parse the data source to generate the tree structure. One is on the server side, and the other is on the browser side. During the render process of the Treeview control, if the treenodesrc is an address, it tries to read the content of the address, parse it, and explicitly write it to the output of the web page, errors are generated here.

My solution is to define an extended attribute treenodesrca, which is not resolved on the server side, but is written to Browser Side in an intact manner. Then HTC of Treeview reads the URL content pointed to by treenodesrca, and parse.

The procedure is as follows:

1. In the Treeview source code Treeview. CS file

Public class Treeview: basepostbackcontrol

To add


/// <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;

}

}

It defines an attribute called treenodesrca.

2. In the Treeview source code Treeview. CS file

Protected override void renderuplevelpath (htmltextwriter output)

Method

If (treenodesrca! = String. Empty)

Output. addattribute ("treenodesrca", treenodesrca );

It is used to write the treenodesrca attribute to the output of the web page if it is not empty.

3. Compile and reference DLL files

4. Add the following to the corresponding locations of Treeview. htc in the Treeview script file:

<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 to define an attribute in HTC, set the variables to store them, and set the method for reading and writing them.

5. In the Treeview script file Treeview. HTC's function oncontentready (),

If (treenodesrc! = NULL)

Before adding:

If (treenodesrca! = NULL)

Treenodesrc = treenodesrca;

This ensures that if the extended attribute treenodesrca is not empty during creation, it will be used to fill the treenodesrc. Then browser will read the data source and parse and bind it.

[Athossmth original, reprinted please note, 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.