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 ForumsClientAPIClientAPIUsing ClientCallBack from JavascriptUsing ClientCallBack from Javascript
Previous
 
Next
New Post
9/21/2006 8:21 AM
 

Is it possible to make a client call back from javascript and use the return with out some control triggering it?

Well my control would trigger the first JS but it would loop through and have to make a few calls to the server -

Or how can I return a whole list of value key pairs and parse them into a list

 

TIA


Dylan Barber http://www.braindice.com - Dotnetnuke development classes - skins and modules
 
New Post
9/21/2006 10:29 AM
 

Is it possible to make a client call back from javascript and use the return with out some control triggering it?

No.  Their needs to be some endpoint defined to receive the call.  This could be the page, or a control within.  Something needs to implemnet the Interface.

Or how can I return a whole list of value key pairs and parse them into a list?

You should definitely minimize the number of callbacks when possible.  Since your callback can return any string, I recommend either returning XML and having the ClientAPI's xml parsing capabilities decipher the return value or probably a better approach would be to use JavaScript Object Notation (JSON).  If it is a really easy list, then simply delimit your list with a "safe" delimiter and use the javascript split method to place it in an array.

 


 
New Post
9/21/2006 10:39 AM
 

Does the clientapi have anyway to generate JSON or xml in the return or do I have to do that?

TIA


Dylan Barber http://www.braindice.com - Dotnetnuke development classes - skins and modules
 
New Post
9/21/2006 1:06 PM
 
Also does anybody have an example of using JSON ?

Dylan Barber http://www.braindice.com - Dotnetnuke development classes - skins and modules
 
New Post
9/21/2006 2:30 PM
 

Funny you should ask about a JSON parser.   I was just investigating whether or not the clientapi should have one, or wait until the framework gets one with the integration of Atlas into the .NET Framework.

I am leaning towards waiting since I have no desire to write that type of code, nor do I have the time to. 

So what do I do in the meantime, since I need this as well.   I am writing my own ToJSON method on my objects I need it.  Eventually I probably will call a serialize method, but for now I am hand-coding each property.  In my case I have a DNNToolBar object with properties, one of which is a Buttons collection, which contains a collection of DNNToolBarButtons.

DNNToolBar.vb

Friend Function ToJSON() As String

Dim oHash As Hashtable = New Hashtable

If Len(Me.CssClass) > 0 Then

oHash.Add("css", "'" & Me.CssClass & "'")

End If

If Me.MouseOutDelay <> 250 Then

oHash.Add("mod", Me.MouseOutDelay)

End If

If Len(Me.Visible) > 0 Then

oHash.Add("vis", CInt(Me.Visible))

End If

Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder

sb.Append("[")

For Each objBtn As DNNToolBarButton In Me.Buttons

If sb.Length > 1 Then sb.Append(",")

sb.Append(objBtn.ToJSON())

Next

sb.Append("]")

oHash.Add("btns", sb.ToString)

sb = New System.Text.StringBuilder

sb.Append("{")

For Each strKey As String In oHash.Keys

If sb.Length > 1 Then sb.Append(",")

sb.Append(strKey & ":" & CStr(oHash(strKey)))

Next

sb.Append("}")

Return sb.ToString

 

DNNToolBarButton.vb

Public Function ToJSON() As String

Dim oHash As Hashtable = New Hashtable

Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder

If Len(Me.CssClass) > 0 Then

oHash.Add("css", "'" & Me.CssClass & "'")

End If

If Len(Me.CssClassHover) > 0 Then

oHash.Add("cssh", "'" & Me.CssClassHover & "'")

End If

If Len(Me.ImageUrl) > 0 Then

oHash.Add("img", "'" & Me.ImageUrl & "'")

End If

If Len(Me.JSFunction) > 0 Then

oHash.Add("js", "'" & Me.JSFunction & "'")

End If

If Len(Me.Key) > 0 Then

oHash.Add("key", "'" & Me.Key & "'")

End If

If Len(Me.NavigateUrl) > 0 Then

oHash.Add("url", "'" & Me.NavigateUrl & "'")

End If

If Len(Me.Text) > 0 Then

oHash.Add("txt", "'" & Me.Text & "'")

End If

If Me.Visible = False Then

oHash.Add("vis", CInt(Me.Visible))

End If

sb.Append("{")

For Each strKey As String In oHash.Keys

If sb.Length > 1 Then sb.Append(",")

sb.Append(strKey & ":" & CStr(oHash(strKey)))

Next

sb.Append("}")

Return sb.ToString

End Function

 

On the Client I simply take the string value and do an eval

 

var oToolBar = eval(myJSON);

 

Then I can do things like oToolbar.css or oToolbar.btns[0].txt

 

 

 


 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Provider and Extension ForumsProvider and Extension ForumsClientAPIClientAPIUsing ClientCallBack from JavascriptUsing ClientCallBack from Javascript


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