How to disable the radscheduler when there's no data

2 posts, 0 answers
  1. Matthew
    Matthew avatar
    16 posts
    Member since:
    Dec 2010

    Posted 22 Feb 2011 Link to this post

    I've a radscheduler reading it's data in from a provider (which connects to exchange). If there's no account to connect to, or a problem with the service, I want the scheduler to simply be disabled and not render.

    So I thought this simple peice of logic would do the trick:

    if (Service != null)
        Calendar.DayStartTime = TimeSpan.Parse("05:00:00");
        Calendar.DayEndTime = TimeSpan.Parse("23:00:00");
        Calendar.Culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB");
        Calendar.WeekView.HeaderDateFormat = "d";
        ScheduleProvider ExchangeScheduleProvider = new ScheduleProvider();
        ExchangeScheduleProvider.ExchangeService = Service;
        Calendar.Provider = ExchangeScheduleProvider;
        Calendar.Enabled = false;
        Calendar.Visible = false;

    However, even though the scheduler shouldn't be enabled now in theory, it seems to ignore this and is desperate to try and databind. I get the following error:

    [ArgumentException: DataKeyField, DataSubjectField, DataStartField and DataEndField are required for databinding]
       Telerik.Web.UI.Scheduling.DataSourceViewSchedulerProvider.EnsureDataFieldsAreSet() +204

    Nowhere in my code do I set a datasource or tell it to databind.
    I don't want it to databind or do anything, how do I disable the control?

  2. Veronica
    Veronica avatar
    1213 posts

    Posted 22 Feb 2011 Link to this post

    Hi Matthew,

    By default RadScheduler can not be shown without first bound to any datasource. Those fields: DataKeyField, DataSubjectField, DataStartField and DataEndField are required otherwise you'll get an error. However you can overcome this by setting those fields to some invalid strings e.g.:

    DataKeyField = "a"
    DataSubjectField ="a"
    DataStartField = "a"

    as their values are checked only for null or empty string.

    As for the RadScheduler to be disabled - please set the ReadOnly property to "true". The Enabled property comes from that the RadScheduler inherits the WebControl class and is common for all controls that inherit the WebControl class.

    All the best,
    Veronica Milcheva
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Back to Top