Export (0) Print
Expand All

TreeView.EnableClientScript Property

Gets or sets a value indicating whether the TreeView control renders client-side script to handle expanding and collapsing events.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

[ThemeableAttribute(false)]
public bool EnableClientScript { get; set; }
<asp:TreeView EnableClientScript="True|False" />

Property Value

Type: System.Boolean
true to render the client-side script on compatible browsers; otherwise, false. The default is true.

Use the EnableClientScript property to specify whether the TreeView control renders client-side script on compatible browsers to handle expanding and collapsing events. When this property is set to true, compatible browsers execute the code to expand and collapse nodes on the client. The tree node data must be known in advance for the client-side script to work. Using client script prevents a post back to the server each time a node is expanded or collapsed.

When the tree node data is not known in advance, nodes can be populated from the client, if the PopulateNodesFromClient property is also set to true. In this scenario, you must also provide an event-handling method for the TreeNodePopulate event to populate the nodes. For more information on client-side node population, see PopulateNodesFromClient.

NoteNote

If the EnableClientScript property is set to false, the TreeView control posts back to the server each time a node is expanded or collapsed.

The value of this property is stored in view state.

This property cannot be set by themes or style sheet themes. For more information, see ThemeableAttribute and ASP.NET Themes and Skins.

This section contains two code examples. The first code example demonstrates how to use the EnableClientScript property to render client-side script that is used to expand and collapse nodes on compatible browsers. The second code example provides sample XML data for the first code example.

The following code example demonstrates how to use the EnableClientScript property to render client-side script that is used to expand and collapse nodes on compatible browsers. Notice that a post to the server is required to expand and collapse a node when the EnableClientScript property is set to false. For this example to work correctly, you must copy the sample XML data, provided after this code example, to a file named Book.xml.



<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeView EnableClientScript Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>TreeView EnableClientScript Example</h3>

      <asp:TreeView id="BookTreeView" 
        DataSourceID="BookXmlDataSource"
        EnableClientScript="true"
        runat="server">

        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Section" TextField="Heading"/>
        </DataBindings>

      </asp:TreeView>

      <asp:XmlDataSource id="BookXmlDataSource"  
        DataFile="Book.xml"
        runat="server">
      </asp:XmlDataSource>

    </form>
  </body>
</html>



The following code example provides sample XML data for the preceding code example.

<Book Title="Book Title">
    <Chapter Heading="Chapter 1">
        <Section Heading="Section 1">
        </Section>
        <Section Heading="Section 2">
        </Section>
    </Chapter>
    <Chapter Heading="Chapter 2">
        <Section Heading="Section 1">
        </Section>
    </Chapter>
</Book>

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft