Setting event colors in a Calendar control

I see that the Calendar control supports setting the colors of events via styles defined in the theme’s CSS files. Is there another way?

I ask because in our app, users can specify the color of an appointment via its corresponding visit type, and we allow them full RGB color picking to do this. So, we can’t do it via the theme’s CSS files - we need a way to directly set an appointment’s color via a color chosen with a colorPicker control (for instance), which would be defined in the visit type, then an appointment has a visit type which gives it its color…

We usually used a simple hack:

  1. Generate CSS classes with names: calendar-color-rrggbb { background-color: rrggbb; }
  2. Enable palette chooser only for ColorPicker so user can choose only one from 32 (or more) colors
  3. Assign named CSS class depending on chosen color from ColorPicker.

@jreznot What about the method I’m finding I’m some searches where you inject CSS styles at runtime via the styles collection of the page?

That could work too, but works slower. In fact users do not need 6 million color combinations, in real life they need something like 10 primary + 30 secondary.