Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checked Change event of tree view is not working

I am working with Treeview control and I am using the following code

  <asp:TreeView ID="tvCategories" ShowCheckBox="False" Style="font-family: Trebuchet MS;
                                    margin-top: 5px; margin-bottom: 5px; margin-left: 20px; color: Black; font-size: 12px"
                                    runat="server" ShowLines="true" NodeIndent="5" OnTreeNodeCheckChanged="tvCategories_TreeNodeCheckChanged"
                                    OnSelectedNodeChanged="tvCategories_SelectedNodeChanged">
                                    <LeafNodeStyle ForeColor="#555555" />
                                    <ParentNodeStyle ForeColor="Black" />
                                    <RootNodeStyle ForeColor="Black" />
                                </asp:TreeView>

Both the OnTreeNodeCheckChanged and OnSelectedNodeChanged are not working and the AutoPostBack property is not available for Treeview.

Please help me out with this issue. Thanks

like image 785
Gitz Avatar asked Oct 01 '14 04:10

Gitz


2 Answers

You need use javascript to make the page postback, then the treenodecheckchanged event can be fired.

like below, you should add the code of bolder to make the page postback.:

 <script language="javascript" type="text/javascript">
     function postBack()
 {
     var element = window.event.srcElement;
     if (element .tagName == "INPUT" && element.type == "checkbox")
     {
        __doPostBack("","");
     } 
 }

</script>

Add the above javascript code in the head section of the page.

onclick="javascript:postBack()"  
like image 144
Neel Avatar answered Sep 29 '22 22:09

Neel


There is no AutoPostBack property for TreeView.

As per the MSDN:

The TreeNodeCheckChanged event is raised when a check box in the TreeView control changes state between posts to the server. This allows you to provide an event-handling method that performs a custom routine, such as updating a database or the displayed content, whenever this event occurs.

You can try javascript to postback the page by adding the onclick event.

Reference: PostBack on selecting checkbox of treeview

like image 44
Vishal Suthar Avatar answered Sep 30 '22 00:09

Vishal Suthar