search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Calendar Won't Refresh

Asked by Phil
10 years ago.

I've got a Calendar on which the background colours of cells is set in the BeforeCellRender event. I've also implemented manual navigation between days, for various reasons. The Calendar is an UpdatePanel. Everything else works perfectly, but for some reason, when I navigate between days, the background cell colouring of the day I navigate to doesn't appear. If I add an event to that day, suddenly the background colouring appears along with the new event.

In my VB.NET which handles the navigation between days, I've included the DataBind() and Update() commands for the Calendar in question. It seems as if adding the new event is forcing the grid to refresh and render the background colours, but for some reason, the DataBind() and Update() commands are not.

Every other action I've implemented that uses the DataBind() and Update() commands works fine. Also, what exactly is the difference between DataBind() and Update()?

Comment posted by Phil
10 years ago.

Looking at the debugger in IE11, when I click the 'Previous Day' button, an error is thrown: "Unable to get property 'style' of undefined or null reference'". Don't think this is anything my code is doing...

Comment posted by Phil
10 years ago.

Ok, I've copied just the relevant controls and code to a new page and run the debugger again, and this time the error wasn't thrown. In fact, no error was thrown, everything seems to run fine, except that my calendar grid isn't redrawn when I navigate backwards and forwards, depsite the DateBind() and Update() commands being present n the code behind. In fact, after doing some testing, it seems that the BeforeCellRender event isn't being triggered by my day navigation at all. If DataBind() and Update() don't trigger BeforeCellRender, what else does?

Comment posted by Phil
10 years ago.

Man, I am totally confused. I thought the BeforeCellRender event wasn't firing because I put a line into the code behind to update the text of a label on the page, which didn't happen. However, the cells in the calendar when the page first loads are being coloured (but still not when I navigate to a different day), as per another line in the BeforeCellRender code behind, so I guess it must be firing, though I don't understand why the label's text isn't being updated.

Comment posted by Phil
10 years ago.

Really feel like this must be a bug. Breaking down the problem very simply, there is code to set the background colour of cells in the BeforeCellRender event. It works when the page containing the Calendar is first loaded. However, when I click a button which changes the StartDate of the Calendar and calls the DataBind() and Update() methods for the Calendar, nothing changes. The same cells stay coloured, no new ones are coloured. However, if I create an Event on the new day, suddenly the whole Calendar is apparently re-rendered, and the background colouring is correct.

I've tried disabling all settings relating to storing the Calendar and Events in ViewState. I've tried taking the Calendar out of the UpdatePanel. Nothing I try works. I just cannot get the Calendar to re-render and colour cells correctly by calling DataBind() and Update().

Answer posted by Phil
10 years ago.

Ok, I've figured this out, or at least worked around it.

My Calendar was in Resources View Mode, and I was defining the columns declaritively in the ASP.NET markup rather than dynamically in the code behind. I had HeaderLevels set to 1, so and each column was for a different resource.

It seems that because the columns in the Calendar represented resources and not dates, when I was navigating between days and data binding, the Calendar didn't think anything had changed so there was no new data to bind. In other words, because the Calendar wasn't displaying any date information in any column heading, changing the Calendar's Start Date didn't actually seem to do anything.

I've gotten around this by setting HeaderLevels to 2, and defining a parent column showing the date and child columns showing the resources, as per the Days Resources View demo on the website (the code is in the downloadable solution). Because I now assign each Resource column a date and/or because I now call the method to define the columns each time a new date is navigated to, the grid now updates as expected.

Thought I'd post this here in case somebody else is struggling with the same problem.

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.