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!