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 ForumsClientAPIClientAPIMy first live page using ClientAPI.  Hurrah!My first live page using ClientAPI. Hurrah!
Previous
 
Next
New Post
3/14/2006 4:31 AM
 

I have a site at www.Stodden.org/Church and if you go there and choose the "Services" page, you can move forward and backward through the monthly schedule - and this is done via the ClientAPI.  It is MUCH quicker than the previous version which used the conventional postback.

Now that I have the first experiment working I will be looking for other pages to convert!

John B

 

 
New Post
3/14/2006 11:49 AM
 

Nice work!

One suggestion.  Make sure you finish your javascript code with a semi-color (;), specifically, chservice.js.


 
New Post
3/14/2006 1:04 PM
 

Noted.  Thanks!

 

 
New Post
4/3/2006 3:19 PM
 

Nice use of the ClientAPI!

Would you mind sharing your code? ... I'm trying to get a understanding of the ClientAPI.

Thanks!

 
New Post
5/2/2006 1:34 PM
 

This is the vb code behind - but bear in mind that it is a first attempt, so may not be "best practice".  The ascx page is just a simple datalist, but there are 2 hidden fields TxtPrev and TxtNext containing the dates of the start of the months.

*************************************************************

Imports DotNetNuke
Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection
Imports DotNetNuke.UI.Utilities
Imports DotNetNuke.UI.Utilities.ClientAPI

Namespace Crownsys.Modules.ChService

    ''' -----------------------------------------------------------------------------
    Partial Class ViewChService
        Inherits Entities.Modules.PortalModuleBase
        Implements Entities.Modules.IActionable
        Implements IClientAPICallbackEventHandler

        Dim LastCaDesc As String = ""
        Dim startd As DateTime

#Region "Event Handlers"
        ''' -----------------------------------------------------------------------------
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try

                If ClientAPI.BrowserSupportsFunctionality(ClientAPI.ClientFunctionality.XMLHTTP) _
                        AndAlso ClientAPI.BrowserSupportsFunctionality(ClientAPI.ClientFunctionality.XML) Then
                    ClientAPI.RegisterClientReference(Me.Page, ClientAPI.ClientNamespaceReferences.dnn_xml)
                    ClientAPI.RegisterClientReference(Me.Page, ClientAPI.ClientNamespaceReferences.dnn_xmlhttp)

                    'Only this line will be necessary after 3.2
                    Me.btPrev.Attributes.Add("onclick", ClientAPI.GetCallbackEventReference(Me, _
                        "dnn.dom.getById('" & Me.txtPrev.ClientID & "').value", _
                        "successFunc", _
                        "'" & Me.ClientID & "'", _
                        "errorFunc"))

                    Me.btNext.Attributes.Add("onclick", ClientAPI.GetCallbackEventReference(Me, _
                        "dnn.dom.getById('" & Me.txtNext.ClientID & "').value", _
                        "successFunc", _
                        "'" & Me.ClientID & "'", _
                        "errorFunc"))

                    If Page.ClientScript.IsClientScriptBlockRegistered("chservice.js") = False Then
                        Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "chservice.js", "<script language=javascript src=""" & Me.ModulePath & "chservice.js""></script>")
                    End If

                End If

                If Not Page.IsPostBack() Then
                    If Session("SchedStartDate") Is Nothing Then
                        startd = New DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)
                        Session("SchedStartDate") = startd
                    Else
                        startd = CType(Session("SchedStartDate"), DateTime)
                    End If
                    txtPrev.Text = startd.AddMonths(-1).ToString()  ' hidden field
                    txtNext.Text = startd.AddMonths(1).ToString()   ' hidden field

                    lblAJAX.Text = GetTableOfServices(startd)

                    If Session("SchedStartDate") Is Nothing Then
                        startd = New DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)
                    Else
                        startd = CType(Session("SchedStartDate"), DateTime)
                    End If

        
                End If

            Catch exc As Exception        'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        Protected Sub lstContent_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles lstContent.ItemDataBound
            Dim strContent As String = ""
            Dim info As ChSuperServiceInfo = e.Item.DataItem

            Dim lblHdr As Label = CType(e.Item.FindControl("lblHdr"), Label)

            If LastCaDesc <> info.CaDesc Then
                LastCaDesc = info.CaDesc
                lblHdr.Text = LastCaDesc
            Else
                lblHdr.Text = ""
            End If

            ' assign the content
            Dim lblType As Label = CType(e.Item.FindControl("lblType"), Label)
            Dim lblTime As Label = CType(e.Item.FindControl("lblTime"), Label)
            Dim lblLoc As Label = CType(e.Item.FindControl("lblLoc"), Label)
            Dim lblSDesc As Label = CType(e.Item.FindControl("lblSDesc"), Label)
            lblType.Text = info.ServiceType()
            lblTime.Text = info.Time()
            lblLoc.Text = info.Loc()
            lblSDesc.Text = info.SDesc()
        End Sub

#End Region

#Region "Optional Interfaces"

etc

#End Region

#Region "Private Functions"

        Private Function GetServiceList() As List(Of ChSuperServiceInfo)
            Dim objChServices As New ChServiceController
            Dim colChServices As List(Of ChSuperServiceInfo)
            Dim d2 As DateTime = New DateTime(startd.Year, startd.Month, startd.Day)
            d2 = startd.AddMonths(1).AddDays(7)
            ' 1 greater than what we need
            ' get the content from the ChService table
            colChServices = objChServices.GetChServices(ModuleId, startd, d2)

            ' bind the content to the repeater if testing against original code
            'lstContent.DataSource = colChServices
            'lstContent.DataBind()
            Return colChServices

        End Function

        Private Function GetTableStart() As String
            Return "<table width=""100%px"" cellpadding=""1"" border=""0"">"
        End Function

        Private Function GetCaDescRow(ByVal caservice As String) As String
            Return "<tr><td colspan=""4"" class=""SubHead"">" & caservice & "</td></tr>"
        End Function

        Private Function GetMonthRow(ByVal startd As Date) As String
            Return "<tr><td colspan=""4"" ><h2>" & String.Format("Schedule for {0}", startd.ToString("MMMM yyyy")) & _
                      "</h2></td></tr>"
        End Function

        Private Function GetTableEnd() As String
            Return "</table>"
        End Function

        Private Function GetTableOfServices(ByVal startd As Date) As String
            Dim listServices As List(Of ChSuperServiceInfo) = GetServiceList()
            Dim sz As String = GetTableStart() & GetMonthRow(startd)
            Dim caservice As String = ""
            Dim chSuper As ChSuperServiceInfo
            For Each chSuper In listServices
                If caservice <> chSuper.CaDesc Then
                    caservice = chSuper.CaDesc
                    sz += GetCaDescRow(caservice)
                End If

                sz += chSuper.ServiceRow(IsEditable(), EditUrl("sid", chSuper.Sid))

            Next
            sz += GetTableEnd()

            Return sz
        End Function
#End Region
       
        Public Function RaiseClientAPICallbackEvent(ByVal eventArgument As String) As String Implements DotNetNuke.UI.Utilities.IClientAPICallbackEventHandler.RaiseClientAPICallbackEvent
            startd = CType(eventArgument, Date)
            Session("SchedStartDate") = New DateTime(startd.Year, startd.Month, 1)
            Return startd.AddMonths(-1).ToString() & "|" & _
               startd.AddMonths(1).ToString() & "|" & GetTableOfServices(startd)
        End Function

    End Class

End Namespace

and this is the little javascript file chservic.js:

 

function successFunc(result, ctx)
{
 var splits = result.split("|");
 dnn.dom.getById(ctx + '_lblAJAX').innerHTML = splits[2];
    dnn.dom.getById(ctx + '_txtPrev').value = splits[0];
 dnn.dom.getById(ctx + '_txtNext').value = splits[1];

   //  alert('result: ' + result + '\ncontext:' + ctx);
}


function errorFunc(result, ctx)
{
 alert(result);
}


Hope that helps!

 

 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Provider and Extension ForumsProvider and Extension ForumsClientAPIClientAPIMy first live page using ClientAPI.  Hurrah!My first live page using ClientAPI. Hurrah!


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