addMarkedTimespan and renderCalendar 'is not a function'

I’m referencing:
dhtmlxscheduler.js
ext/dhtmlxscheduler_minical.js
ext/dhtmlxscheduler_limit.js

but I’m getting ‘TypeError: scheduler.addMarkedTimespan is not a function’. I can see addMarkedTimespan in dhtmlxscheduler_limit.js so not sure what is causing the error.

I’m relatively new to ASP.NET, I’m not using MVC. I’m using the ASP.NET v3.0 dhtmlxScheduler.

I had the same error but with renderCalendar, for a mini calendar seperate to the scheduler, so I decided to use the jquery DatePicker plugin to get going but ideally I’d like to use the matching minical. Here is part of my client side code, hope someone might be able to help:

$('#cal_here').DatePicker({ date: new Date(), flat: true, calendars: 1, onChange: function () { $('#seldate').val($('#cal_here').DatePickerGetDate(true)); scheduler.addMarkedTimespan({ start_date: $('#seldate').val(), end_date: $('#seldate').val(), css: "green_section" }); scheduler.setCurrentView($('#seldate').val()); __doPostBack('upMap', ''); } });

The onChange function of the date picker fires ok (everything else is ok) and I can step through to the point where it has finished getting the options values for addMarkedTimespan then it gives the above error.
Thanks

Hi,
make sure that urls to the limit and minicalendar extensions are correct - check the developer tools console for 404 errors.
The functions are defined in these files, if they are not defined - this probably means that files are not loaded

Thanks for the suggestion, I’m not seeing any 404 errors in the console and I can see the contents of the scripts in the loaded HTML.

I tried changing the URL to the file to a wrong one to check I got a 404 and I did then, so it seems to be finding the file ok. Do you have any other ideas?

Hi,
there are not many possible reasons why object properties or method which are defined in a js file may be not accessable from the code

  1. Either dhtmlxscheduler_limit.js or in dhtmlxscheduler_minical.js or both are corrupted, i.e. code contains syntax errors. In this case the code won’t be executed and methods won’t be defined and you’ll see a message about syntax error in console.

  2. dhtmlxscheduler_limit.js or in dhtmlxscheduler_minical.js are not loaded to the page where you calling scheduler.addMarkedTimespan. In this case you would see 404 error in console and network tab.
    If you use PRO version of the scheduler, it may also happen if you create instance of the scheduler before loading extension files

  3. Files are loaded correctly and methods added, but the scheduler object is redefined after that. which means reseting all added methods. It will happen if you load files in following order:

    1. dhtmlxscheduler.js
    1. dhtmlxscheduler_limit.js
    1. dhtmlxscheduler_minical.js
    1. dhtmlxscheduler.js//load second time, all extensions will be reset
  1. The methods are manually deleted by the custom code. You may set couple of breakpoints in the client-side code and check at which point scheduler.addMarkedTimespan becomes undefined

  2. It’s also possible that you’ve redefined ‘scheduler’ variable somewhere in a function scope, so it contains some custom value and not pointing to global dhtmlxScheduler object.
    E.g. following code would have caused such error, without breaking the rest of application:[code](function(){

    var scheduler = {};//empty object

    $(’#cal_here’).DatePicker({
    date: new Date(),
    flat: true,
    calendars: 1,
    onChange: function () {
    $(’#seldate’).val($(’#cal_here’).DatePickerGetDate(true));
    scheduler.addMarkedTimespan({ start_date: $(’#seldate’).val(), end_date: $(’#seldate’).val(), css: “green_section” });
    scheduler.setCurrentView($(’#seldate’).val());
    __doPostBack(‘upMap’, ‘’);
    }
    });
    })();[/code]

That should be pretty it. I would expect that problem is caused by a files order or something related.
If nothing helps - please give a link to the page where it can be checked

Thankyou very much. The problem was I was using the server side Render() function for the scheduler which I hadn’t noticed was putting its own script tag in, so as you suggested it seemed to be the double loading causing it as when I removed my own one and moved the limit and minical files to the bottom of the page it started working.
The addMarkedTimespan() and renderCalendar() seem to be working now.
Thanks for your help.

You can enable extensions in server-side config, so DHXScheduler.Render() will render all necessary links:
c#:scheduler.Extensions.Add(SchedulerExtensions.Extension.Limit); scheduler.Extensions.Add(SchedulerExtensions.Extension.Minical);
Alternatively, server side can render only required html markup and JS code (without tags for required JS/CSS files). Then you’ll add all required files to the page manually. Here is the method:

DHXScheduler.GenerateHTML(); //instead of DHXScheduler.Render()
Otherwise you’ll have to remember which files are added by server-side component, and which have to be added to the page manually

Thanks