I have had the same problem.
I managed to find a workaround, not very elegant though. Code is in C#
in .aspx
make Treeview1.AutoPostback = false
add an hidden input field (tbSelectedNode), don't forget to make it RunAtServer
add a asp:Button (btnPost), I made this 1px high 1px wide so you can't see it
add a javascript function in the HEAD section for the events to handle
<script type="text/javascript">
function nodepostback()
{
var postback = document.getElementById('btnPost');
var hidden = document.getElementById('tbSelectedNode');
var treeview = document.getElementById('tvMeterGroups');
if(hidden != null && treeview != null)
{
if(*** enter your condition for posting here, if you want one ***)
{
hidden.value = treeview.selectedNodeIndex;
postback .click();
}
}
return false;
};
</script>
in code behind .aspx.cs
add the handlers for the events you want to handle, in the Page_Load like this:
Treeview1.Attributes.Add("onselectedindexchange", "javascript:nodepostback();");
add a page private static string variable:
private static string strSelectedNode = "";
add a click handler for the button
private void btnPost_Click(object sender, System.EventArgs e)
{
strSelectedNode = tbSelectedNode.Value;
....
....
}
add PreRender for the treeview, to ensure the selection gets made
private void Treeview1_PreRender(object sender, System.EventArgs e)
{
Treeview1.SelectedNodeIndex = strSelectedNode;
}
The above worked for me when all I wanted was 'onselectedindexchange' postback.
I tried 'return false' handlers for the other events, when I had AutoPoasback=true, but that caused the control to lose collapsed/expanded info.
I tried to remove attributes for the events I didn't want posted back in PreRender but that didn't remove them when I viewed source.
This was all I could get to work.
I hope this may help others who have similar problems.