Rediger

Del via


TreeView.EnableClientScript Property

Definition

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

public:
 property bool EnableClientScript { bool get(); void set(bool value); };
[System.Web.UI.Themeable(false)]
public bool EnableClientScript { get; set; }
[<System.Web.UI.Themeable(false)>]
member this.EnableClientScript : bool with get, set
Public Property EnableClientScript As Boolean

Property Value

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

Attributes

Examples

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>

<%@ Page Language="VB" %>

<!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>

Remarks

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.

Note

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.

Applies to

See also