将 AsyncPostBackTrigger 添加到第二个 updatePanel,以便在触发 TreeView Click 事件时对其进行更新。
<Asp:UpdatePanel id="UP2">
<View1/>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="TreeView1" EventName="Click" />
</Triggers>
</Asp:UpdatePanel>
好的,这是一个工作示例。
标记:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<table style="width: 100%;">
<tr>
<td>
<asp:UpdatePanel ID="upTreeView" runat="server">
<ContentTemplate>
<asp:TreeView ID="TreeView1" runat="server"
onselectednodechanged="TreeView1_SelectedNodeChanged">
<Nodes>
<asp:TreeNode Text="GrandFather" Value="GrandFather">
<asp:TreeNode Text="Father" Value="Father">
<asp:TreeNode Text="Son" Value="Son"></asp:TreeNode>
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td>
<asp:UpdatePanel ID="upView" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="TreeView1"
EventName="SelectedNodeChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
后面的代码:
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
Label1.Text = TreeView1.SelectedValue;
}