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

Unexpected Number When Opening Add Event Dialog

Asked by Chase
9 years ago.

Hello,

I am following the tutorial for adding an event to the scheduler. I am doing it slightly different however; I am using code behind to call the javascript function that will open the dialog.

Page page = HttpContext.Current.CurrentHandler as Page;
page.ClientScript.RegisterStartupScript(typeof(Page), "Test", "<script type='text/javascript'>timeRangeSelected(" + e.Start + ", " + e.End + ", " + e.Resource + ");</script>");

This calls the javascript function `timeRangeSelected`

function timeRangeSelected(start, end, resource) {
var modal = new DayPilot.Modal();

modal.top = 60; //This is where the modal is positioned.
modal.width = 600;
modal.height = 500;
modal.opacity = 70;
modal.border = "10px solid #d0d0d0";
modal.closed = function () {

//update the scheduler now that the modla has been closed.
dps1.commandCallBack('refresh');
dps1.clearSelection();
};
modal.showUrl("NewEvent.aspx?start=" + start.toStringSortable() + "&end=" + end.toStringSortable() + "&r=" + resource);
}

Inside my Scheduler I have the TimeRangeSelectedHandling to Postback so the code behind will execute. The reason I am using the code behind is because I was to set the date of the my datepickers to the time range selected (the user wont have to input a date or resource).

If I set the TimeRangeSelectedHandling to javascript the dialog will appear and I can add an event (but not set the date or the resource to what the user selected in the time range).

If I have the TimeRangeSelectedHandling set to PostBack I get the following error in the console:

"Uncaught Syntax Error: Unexpected Number"

on this line:

<script type='text/javascript'>timeRangeSelected(4/13/2015 12:00:00 AM, 4/19/2015 12:00:00 AM, 106);</script>

I think maybe has something to do with the format that the date is in? Any help will be greatly appreciated.

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

You need quotes around the parameters so it produces something like this:

timeRangeSelected('4/13/2015 12:00:00 AM', '4/19/2015 12:00:00 AM', '106');

Try this:

page.ClientScript.RegisterStartupScript(typeof(Page), "Test", "<script type='text/javascript'>timeRangeSelected('" + e.Start.ToString("s") + "', '" + e.End.ToString("s") + "', '" + e.Resource + "');</script>");

This will convert the strings to ISO 8601 format (yyyy-MM-ddTHH:mm:ss) and add single quotes.

Then change the last call in the function to add the parameters to the query string without modification:

modal.showUrl("NewEvent.aspx?start=" + start + "&end=" + end + "&r=" + resource); 

Let me know if it didn't help.

Comment posted by Chase
9 years ago.

This worked perfect. Thank you!

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