Javascript 在页面加载c上添加脚本#
我正在尝试向页面添加脚本,但什么也没有发生,日历没有显示。 目标是呈现一个包含事件列表的日历,我试图避免使用Web服务来获取列表Javascript 在页面加载c上添加脚本#,javascript,c#,asp.net,Javascript,C#,Asp.net,我正在尝试向页面添加脚本,但什么也没有发生,日历没有显示。 目标是呈现一个包含事件列表的日历,我试图避免使用Web服务来获取列表 string CalendarScript = @"<script type=""text/javascript""> jQuery(function ($) { /* initialize the external events ------------------------
string CalendarScript = @"<script type=""text/javascript"">
jQuery(function ($) {
/* initialize the external events
-----------------------------------------------------------------*/
$('#external-events div.external-event').each(function () {
// create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
// it doesn't need to have a start or end
var eventObject = {
title: $.trim($(this).text()) // use the element's text as the event title
};
// store the Event Object in the DOM element so we can get to it later
$(this).data('eventObject', eventObject);
// make the event draggable using jQuery UI
$(this).draggable({
zIndex: 999,
revert: true, // will cause the event to go back to its
revertDuration: 0 // original position after the drag
});
});
/* initialize the calendar
-----------------------------------------------------------------*/
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
lang: ""pt"",
allDaySlot: false,
minTime: ""07:00:00"",
maxTime: ""23:59:59"",
defaultView: 'agendaWeek',
header: {
left: ' ',
center: ' ',
right: ' '
},
events: [ " + EventsList + @"
]
,
columnFormat: {
week: 'dddd',
},
editable: false,
droppable: false, // this allows things to be dropped onto the calendar !!!
selectable: false,
selectHelper: false
});
})
</script>";
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "InitCalendarEvents", CalendarScript, false);
两件事。首先,当您使用脚本管理器注册脚本时,它应该只是javascript,而不是封装在脚本标记中。其次,您很可能希望函数发生在add_load事件上 这是一个示例代码段:
this.Page.ClientScript.RegisterStartupScript(
this.GetType(),
"StartupScript",
"Sys.Application.add_load(function() { functioncall(); });",
true);
请注意,javascript函数的参数是javascript函数,而不是html脚本元素。此外,该函数并不是由Sys.Application.add\u load
如果您做了这两件事,至少应该执行脚本。这个问题可能与你想做什么有关
this.Page.ClientScript.RegisterStartupScript(
this.GetType(),
"StartupScript",
"Sys.Application.add_load(function() { functioncall(); });",
true);