Posting here for the benefit of others who are attempting to learn the ClientAPI and may have encountered similar obstacles...
I have recently been working through the ClientAPI documents and examples in hopes of utilizing this great functionality within my custom modules. Using the CallbackWithEvents sample as a guide, I had been unable to access form data from within the RaiseClientAPICallbackMethod. After much trial and error I decided to setup the handler to capture and return all form data transmitted within the ClientCallback, at which point I recognized the root cause of my issue: the use of Request[Control.ClientId] to retrieve the form data.
The CallbackWithEvents sample demonstrates successful post and retrieval of form data using ClientCallback functionality. Within the Callback method the form data is retrieved as below:
Public Function RaiseClientAPICallbackEvent(ByVal eventArgument As String) As String Implements UI.Utilities.IClientAPICallbackEventHandler.RaiseClientAPICallbackEvent
Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder
sb.Append(Now.ToString & vbCrLf)
sb.Append(Me.txt.ClientID & ": " & Request(Me.txt.ClientID) & vbCrLf)
sb.Append(Me.cbo.ClientID & ": " & Request(Me.cbo.ClientID) & vbCrLf)
sb.Append(Me.ta.ClientID & ": " & Request(Me.ta.ClientID) & vbCrLf)
sb.Append(Me.chk.ClientID & ": " & Request(Me.chk.ClientID) & vbCrLf)
sb.Append("myvar: " & DotNetNuke.UI.Utilities.ClientAPI.GetClientVariable(Me.Page, "myvar") & vbCrLf)
Return sb.ToString
End Function
This approach seems to work fine within the example, because all form controls are located in the main NamingContainer of the Page control. In my case, I had been attempting to use the same approach from within the context of a module. Like the example, I coded my callback to refer to the form controls using their ClientID property...
this.Page.Request[this.txtName.ClientId];
Me.Page.Request(Me.txtName.ClientId)
... thus ensuring that I would be requesting the control by the unique name that was rendered to the client and thus posted through the callback. This is pretty common when dealing with the client-side representation of asp.net controls... was working fine in John's example... but was not working for me!
Turns out that UniqueId is the more-appropriate control identifier to use in this scenario. I hadn't considered this until now, but it seems that many form controls are rendered using their UniqueID as opposed to their ClientID (I'm not exactly sure why as I haven't come accross an explanation).
As mentioned before, the ClientID approach works fine in John's simple example because all controls are in the base/highest naming container, thus there is no need for .NET to prefix the controls with any parent naming containers... and thus there are no delimiters involved. However if you wish to use an approach similar to the CallbackWithEvents example, and you are using said approach from within the context of a DNN module, you'll need to retrieve your form data as demonstrated in teh updated code below.
Public Function RaiseClientAPICallbackEvent(ByVal eventArgument As String) As String Implements UI.Utilities.IClientAPICallbackEventHandler.RaiseClientAPICallbackEvent
Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder
sb.Append(Now.ToString & vbCrLf)
sb.Append(Me.txt.ClientID & ": " & Request(Me.txt.UniqueID) & vbCrLf)
sb.Append(Me.cbo.ClientID & ": " & Request(Me.cbo.UniqueID) & vbCrLf)
sb.Append(Me.ta.ClientID & ": " & Request(Me.ta.UniqueID) & vbCrLf)
sb.Append(Me.chk.ClientID & ": " & Request(Me.chk.UniqueID) & vbCrLf)
sb.Append("myvar: " & DotNetNuke.UI.Utilities.ClientAPI.GetClientVariable(Me.Page, "myvar") & vbCrLf)
Return sb.ToString
End Function
Best Regards,
Chris