This is a migrated thread and some comments may be shown as answers.

Losing programatically created CalendarDayTemplates on postback

1 Answer 24 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Glenn Boothe
Top achievements
Rank 1
Glenn Boothe asked on 15 Jun 2010, 01:44 PM
I've got a calendar that has CalendarDayTemplates created dynamically on load and then assigns each one to a SpecialDay in the calendar. Please see below.

            If Not IsPostBack Then
                Dim i as Integer = 0

                For Each d As RadDate In cal.SelectedDates 
                    dvTimespots.RowFilter = "startdate <= #" & d.Date & "# AND enddate >= #" & d.Date & "#"
 
                    Dim cdt As New CalendarDayTemplate(d.Date.Day, dvTimespots.Count & " media item(s)"
                    Dim dt As New DayTemplate 
                    With dt 
                        .Content = cdt 
                        .ID = i 
                    End With 
                    cal.CalendarDayTemplates.Add(dt) 
 
                    Dim rcd As New RadCalendarDay 
                    With rcd 
                        .Date = d.Date 
                        .TemplateID = i 
                    End With 
 
                    cal.SpecialDays.Add(rcd) 
 
                    i += 1 
                Next
            End If

This works great when the page is not postback, but on any postback I get this error:
System.Exception: Template with ID: 0 not found.

I'm assuming that's because the first special day rendered has a TemplateID of 0, which is not being persisted.

Is this expected functionality? Is there a workaround without re-running the above?



1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 18 Jun 2010, 10:35 AM
Hello Glenn,

When creating DayTemplate dynamically, you should do it on each page load.
If you do not want to query your database on each page load in your case, you can get the desired data once on initial load and save is in a variable you would use later on.

Sincerely yours,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Calendar
Asked by
Glenn Boothe
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or