Losing programatically created CalendarDayTemplates on postback

2 posts, 0 answers
  1. Glenn Boothe
    Glenn Boothe avatar
    21 posts
    Member since:
    Jul 2008

    Posted 15 Jun 2010 Link to this post

    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 
                        Dim rcd As New RadCalendarDay 
                        With rcd 
                            .Date = d.Date 
                            .TemplateID = i 
                        End With 
                        i += 1 
                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?

  2. Iana Tsolova
    Iana Tsolova avatar
    3388 posts

    Posted 18 Jun 2010 Link to this post

    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,
    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
  3. DevCraft R3 2016 release webinar banner
Back to Top