简体   繁体   中英

Treeview asp.net

I have a treeview control on an asp.net page. Everytime I select a node in the tree, a duplicate copy of the tree is displayed under it. I am unable to understand. I have not written any code so far. I'm probably missing out on some property that I should have set. No matter which node I click on another tree is displayed under the existing tere. Please help!

It sounds like you're adding the Treeview to the page on Page_Load without testing if it's a Postback or not.

If it's a Postback then the Treeview will be automatically added to the page as the WebForm reconstructs itself.

Try this:

void Page_Load() {

    if( !Page.IsPostback ) {

    // code to add treeview to page
    }
}

That said - I strongly advice staying away from the WebForms Treeview control (and generally speaking, anything in the System.Web.UI.WebControls namespace - except for Literal and PlaceHolder) because they take away too much control from the developer and often end up wrecking the user experience. The WebControls library was originally designed around IE6, many years ago.

If you're starting a new project I strongly recommend you take a look at ASP.NET MVC instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM