TreeView.EnableClientScript 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定值,指出 TreeView 控制項是否呈現用戶端指令碼,以處理展開和摺疊事件。
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
屬性值
true
表示在相容的瀏覽器上呈現用戶端指令碼,否則為 false
。 預設為 true
。
- 屬性
範例
本節包含兩個程式碼範例。 第一個程式碼範例示範如何使用 EnableClientScript 屬性來轉譯用戶端腳本,以在相容的瀏覽器上展開和折迭節點。 第二個程式碼範例會針對第一個程式碼範例提供範例 XML 資料。
下列程式碼範例示範如何使用 EnableClientScript 屬性來轉譯用戶端腳本,以在相容的瀏覽器上展開和折迭節點。 請注意,當 屬性設定 false
為 時 EnableClientScript ,需要對伺服器進行貼文,才能展開和折迭節點。 若要讓此範例正常運作,您必須將此程式碼範例之後提供的範例 XML 資料複製到名為 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>
下列程式碼範例提供上述程式碼範例的 XML 資料範例。
<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>
備註
EnableClientScript使用 屬性可指定控制項是否會 TreeView 在相容的瀏覽器上轉譯用戶端腳本,以處理展開和折迭事件。 當此屬性設定為 true
時,相容的瀏覽器會執行程式碼來展開和折迭用戶端上的節點。 用戶端腳本必須事先知道樹狀節點資料才能運作。 每次展開或折迭節點時,使用用戶端腳本可防止回傳至伺服器。
當事先不知道樹狀節點資料時,如果 PopulateNodesFromClient
屬性也設定為 true
,則可以從用戶端填入節點。 在此案例中,您也必須提供事件的事件處理方法 TreeNodePopulate ,以填入節點。 如需用戶端節點母體擴展的詳細資訊,請參閱 PopulateNodesFromClient 。
注意
EnableClientScript如果 屬性設定為 false
,則控制項會在 TreeView 每次展開或折迭節點時回傳至伺服器。
此屬性的值會儲存在檢視狀態中。
這個屬性無法由佈景主題或樣式表主題設定。 如需詳細資訊,請參閱 ThemeableAttribute 和 ASP.NET 主題和麵板。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應