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(orPage_Init, whatever) regardless ofthis.Page.IsPostbackIf you rebind your
TreeViewbefore theEventHandleris reached in the Asp.net Lifecycle, you will suppress all events that should be raised, e.g. yourOnTreeNodeCheckedChangedeventOnly bind upon
Upon postbacks you have to rebind after the desired event handlers have been executed
Edit:
You need to manually force a
PostBack, because theTreeViewwon’t fire aPostbackchanging the Checked property of the rendered checkboxes.TreeView.TreeNodeCheckChanged Event