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; }
/** @property */
public boolean get_EnableClientScript ()

/** @property */
public void set_EnableClientScript (boolean value)

public function get EnableClientScript () : boolean

public function set EnableClientScript (value : boolean)

Not applicable.

Property Value

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 Introduction to ASP.NET Themes.

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>

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft