开发者

TreeNodeCheckChanged is not working in my ASP.Net application

开发者 https://www.devze.com 2023-02-03 14:43 出处:网络
TreeNodeCheckChanged is not working in my ASP.Net application. 开发者_运维百科<asp:TreeView ID=\"TreeView1\" ShowCheckBoxes=\"All\" runat=\"server\"

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号