You problem is in the assumption that this contains the node that was clicked. Instead this contains a reference to the treeview control itself. To get a reference to the selected node you would use this.selTreeNode.
What I am confused about is the statement that your first example worked... I don't see how it could. Here is a complete example (separate from DNN).
ASPX
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="DNNTreeCallback.aspx.vb" Inherits="DotNetNuke.WebControls.Test.DNNTreeCallback"%>
<%@ Register TagPrefix="DNN" Namespace="DotNetNuke.UI.WebControls" Assembly="DotNetNuke.WebControls" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script language=javascript>
<!--
function callbackSuccess(result, ctx)
{
alert(result);
alert(ctx.key); //NodeID
}
function callbackError(result, ctx)
{
alert(result);
}
//-->
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<DNN:DNNTree id="MyDNNTree" runat="server" TreeScriptPath="js/"></DNN:DNNTree>
</form>
</body>
</HTML>
CodeBehind
Imports DotNetNuke.UI.WebControls
Public Class DNNTreeCallback
Inherits System.Web.UI.Page : Implements DotNetNuke.UI.Utilities.IClientAPICallbackEventHandler
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents MyDNNTree As DotNetNuke.UI.WebControls.DnnTree
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim oNode As TreeNode = New TreeNode("ROOT")
Me.MyDNNTree.TreeNodes.Add(oNode)
Dim oNode2 As TreeNode = New TreeNode("DoCallBack")
oNode2.Key = "MyKey"
oNode2.ID = "MyID"
oNode2.JSFunction = DotNetNuke.UI.Utilities.ClientAPI.GetCallbackEventReference(Me, "this.selTreeNode.id", "callbackSuccess", "this.selTreeNode", "callbackError")
oNode.TreeNodes.Add(oNode2)
End Sub
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
MyBase.OnInit(e)
DotNetNuke.UI.Utilities.ClientAPI.HandleClientAPICallbackEvent(Me)
End Sub
Public Function RaiseClientAPICallbackEvent(ByVal eventArgument As String) As String Implements UI.Utilities.IClientAPICallbackEventHandler.RaiseClientAPICallbackEvent
Return eventArgument & " " & Now.ToString
End Function
End Class