使用UpdatePanel for asp.net树视图SelectedNodeChanged事件

时间:2013-04-24 12:05:30

标签: c# asp.net textbox treeview updatepanel

我有TextBoxtreeview喜欢,

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtName" runat="server" Width="150px" ReadOnly="true"
BorderStyle="Double">
</asp:TextBox>
</ContentTemplate>  
</asp:UpdatePanel>  

<asp:TreeView ID="TreeView1" runat="server" ImageSet="Arrows"   
OnSelectedNodeChanged="TreeView1_SelectedNodeChanged" >
<NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px"
NodeSpacing="0px" VerticalPadding="0px" />
<SelectedNodeStyle CssClass="treeHover"></SelectedNodeStyle>
</asp:TreeView>

SelectedNodeChanged事件的编码,

protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{      
    txtName.Text = TreeView1.SelectedNode.Text;
}

我的更新面板无法正常工作,我想知道我的代码中有什么问题?

1 个答案:

答案 0 :(得分:4)

试试这个......

 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
    <asp:TextBox ID="txtName" runat="server" Width="150px" ReadOnly="true"
    BorderStyle="Double">
    </asp:TextBox>
    </ContentTemplate>  
     <Triggers>
            <asp:AsyncPostBackTrigger ControlID="TreeView1" EventName="SelectedNodeChanged" />
            </Triggers>
    </asp:UpdatePanel>  

    <asp:TreeView ID="TreeView1" runat="server" ImageSet="Arrows"   
    OnSelectedNodeChanged="TreeView1_SelectedNodeChanged" >
    <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px"
    NodeSpacing="0px" VerticalPadding="0px" />
    <SelectedNodeStyle CssClass="treeHover"></SelectedNodeStyle>
    </asp:TreeView>