I have a requirement to build a treeview dynamically. Each node on the treeview has a label and two checkboxes. I have tried two different methods to build the treeview. In Case 1, I created a node template that includes the label and two checkboxes. In Case 2, I do not use a template, but rather I simply add the label and two checkboxes to the node control collection. I loop through the node collection to set the checkboxes Checked property after I have added all of the nodes to the treeview. In Case 1, I build the nodes and add the nodes to the treeview in the Page_Init event. In Case 2, I have tried building the nodes and adding the controls in both Page_Init and Page_Load events.
When I run the page, I change the state of some of the checkboxes in some nodes. Then I do a postback. On the return from the postback, everything displays correctly (maintaining the correct state of the checkboxes). If I build the dynamic treeview in the Page_Load event, I am not able to correctly maintain the checkboxes state. In Case 2, everything works fine on the first postback. Then if I make additional changes to the checkboxes and resubmit, the return from the postback does NOT maintain the correct state of the checkboxes. Even if I do not make any changes to the checkboxes, but just submit unchanged values, the return screen has changed the values of the checkboxes. (This is true regardless of whether I build the treeview in Page_Init or Page_Load)
Does anyone have any advice on how to maintain the correct state of controls added dynamically to nodes in a treeview?
When I run the page, I change the state of some of the checkboxes in some nodes. Then I do a postback. On the return from the postback, everything displays correctly (maintaining the correct state of the checkboxes). If I build the dynamic treeview in the Page_Load event, I am not able to correctly maintain the checkboxes state. In Case 2, everything works fine on the first postback. Then if I make additional changes to the checkboxes and resubmit, the return from the postback does NOT maintain the correct state of the checkboxes. Even if I do not make any changes to the checkboxes, but just submit unchanged values, the return screen has changed the values of the checkboxes. (This is true regardless of whether I build the treeview in Page_Init or Page_Load)
Does anyone have any advice on how to maintain the correct state of controls added dynamically to nodes in a treeview?