Pouvez-vous jeter un oeil sur le code ci-dessous et dites-moi comment je peux résoudre ce problème. Chaque fois que le jour est rendu dans le calendrier, il appelle un webservice (service.EventGetList ("ALL") ). Cela provoque une page très lente. Comment puis-je appeler le service Web une seule fois et obtenir les mêmes résultats?ASP.NET jour rendu
Protected Sub calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles calendar1.DayRender
WordFoundAt = -1 'not found
'declare a new dataset
Dim ds As New DataSet("MyDataSet")
'declare a new datatable
Dim dTable As New DataTable("EventsData")
'decalre a new datarow
Dim dr As DataRow
'assign all events from the webservice
openEvents = service.EventGetList("ALL")
'build the columns for the datatable
dTable.Columns.Add("Id", GetType(String))
dTable.Columns.Add("Title", GetType(String))
dTable.Columns.Add("EventStart", GetType(DateTime))
dTable.Columns.Add("EventEnd", GetType(DateTime))
Dim dr1 As DataRow()
' ds.Tables.Add(dTable)
Dim i As Integer = 0
For Each currEvent In openEvents
'assign local variables to the properties of the events in the array
id1 = openEvents(i).id
Title = openEvents(i).Title
eventStart = openEvents(i).EventStart
eventEnd = openEvents(i).EventEnd
dr = dTable.NewRow()
dr.Item("Id") = id1
dr.Item("Title") = Title
dr.Item("EventStart") = eventStart
dr.Item("EventEnd") = eventEnd
dTable.Rows.Add(dr)
i = i + 1
Next
'do a select on the datatable and filter the results to give you the events for the day of the cell
' as this method gets executed every time the cell is created, the calender control creates the cells 1 x1
dr1 = dTable.Select(String.Format("EventStart >= #{0}# AND EventStart < #{1}#", e.Day.Date.ToLongDateString(), e.Day.Date.AddDays(1).ToLongDateString()))
'local counter variables
Dim x As Integer = 0
Dim y As Integer = 0
Dim a As String
'loop to add all available event dates to an array
For Each dr In dr1
datearray(y) = dr.Item("EventStart")
idarray(y) = dr.Item("Id")
y = y + 1
Next
'delcare variables for flag true/false
'loop
For Each dr In dr1
'pull event date from previous array and assign it to local variable
a = datearray.GetValue(x)
'assign current event date to local variable WordToFind
WordToFind = dr.Item("EventStart")
' test if the current event date = what ever is in the array of events and the flag is false
If WordToFind = a Then
'if the cell has a control on it (i.e the Image of the X)
If Not e.Cell.Controls.Count > 1 Then
e.Cell.CssClass = "event"
Else
End If
End If
x = x + 1
Next
End Sub