TreeNodeCheckChanged
is not working in my ASP.Net application.
开发者_运维百科<asp:TreeView ID="TreeView1" ShowCheckBoxes="All" runat="server"
OnTreeNodeCheckChanged="TreeView1_TreeNodeCheckChanged">
</asp:TreeView>
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.IsPostBack)
{
TreeView(); //bind manually
}
}
How can I fix this ?
How are you binding your TreeView
?
I guess you are binding on every Page_Load
(or Page_Init
, whatever) regardless of this.Page.IsPostback
If you rebind your TreeView
before the EventHandler
is reached in the Asp.net Lifecycle, you will suppress all events that should be raised, e.g. your OnTreeNodeCheckedChanged
event
Only bind upon
if(!this.Page.IsPostBack)
{
// insert your initial binding of your treeview here
}
Upon postbacks you have to rebind after the desired event handlers have been executed
Edit:
You need to manually force a PostBack
, because the TreeView
won't fire a Postback
changing the Checked property of the rendered checkboxes.
Even though the
TreeNodeCheckChanged
event is fired on post back, changing a check box does not cause a post back.
TreeView.TreeNodeCheckChanged Event
精彩评论