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

JavaScript runtime error: Unable to get property 'clientWidth' of undefined or null reference on Scheduler

Asked by Tony
8 years ago.

I'm trying to implement a client side function to allow a user to re-focus the scheduler on today's date.

Here's my code:

function ScrollToToday() {
var dp = new DayPilot.Scheduler("<%= DayPilotScheduler1.ClientID%>");
dp.scrollTo("2015-09-11");
}

demo.aspx (code that shows the scheduler)
<DayPilot:DayPilotScheduler ID="DayPilotScheduler1" runat="server" DataStartField="eventstart" DataEndField="eventend" DataTextField="name" DataValueField="id"
DataResourceField="resource_id"
CellGroupBy="Month"
CellDuration="1440"
StartDate="2009-01-01"
Days="365"
Width="100%"
EventHeight="25"
Height="450px"
HeightSpec="Max"
Theme="scheduler_8"

RowHeaderWidth="120">
</DayPilot:DayPilotScheduler>

I also have an input button that calls the function. When I execute, I get a JavaScript error:
"JavaScript runtime error: Unable to get property 'clientWidth' of undefined or null reference"

Can anyone tell me what I'm doing wrong?

Answer posted by Dan Letecky [DayPilot]
8 years ago.

The DayPilot.Scheduler instance is created automatically using the <DayPilot:DayPilotScheduler> tag. The ScrollToToday() method tries to create a new instance:

function ScrollToToday() { 
  var dp = new DayPilot.Scheduler("<%= DayPilotScheduler1.ClientID%>"); 
  dp.scrollTo("2015-09-11"); 
}

You can add ClientObjectName="dp" property to give the instance a fixed name:

<DayPilot:DayPilotScheduler 
  ID="DayPilotScheduler1" 
  runat="server" 
  ClientObjectName="dp"
  ...
> 
</DayPilot:DayPilotScheduler>

Then you will be able to access the Scheduler client-side object using "dp" variable:

function ScrollToToday() { 
  dp.scrollTo("2015-09-11"); 
}
Comment posted by Tony
8 years ago.

Thanks Dan - that sorted it instantly!

Really appreciate the quick reply.

Tony

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