Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Provider and Extension ForumsProvider and Extension ForumsClientAPIClientAPICallbackWithEvents Example - Key LearningCallbackWithEvents Example - Key Learning
Previous
 
Next
New Post
1/10/2007 7:02 PM
 

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

 
New Post
1/11/2007 10:24 AM
 

Thanks for sharing your findings.  I commonly confuse the two and as you have pointed out my example is using the wrong one.  My intention was to show support for naming containers with it, but obviously it was not caught since my sample did not use naming containers.  I will modify the sample code.

Thanks again!


 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Provider and Extension ForumsProvider and Extension ForumsClientAPIClientAPICallbackWithEvents Example - Key LearningCallbackWithEvents Example - Key Learning


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out