This is a migrated thread and some comments may be shown as answers.

Javascript Error When Exporting to iCalendar

6 Answers 72 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Jon Ingersoll
Top achievements
Rank 1
Jon Ingersoll asked on 14 Sep 2009, 07:49 PM
I'm following the instructions on:
http://www.telerik.com/help/aspnet-ajax/schedule_howtoexportingtoicalendar.html

to add the export feature to our online calendar already in production.  Per the instructions I've added the code block to the .ascx:
                <div style="text-align: right;"
                     <span style="cursor: pointer; cursor: hand;"
                     <asp:ImageButton runat="server" ID="Button1" ImageUrl="Outlook.gif" AlternateText="Export to iCalendar" 
                     CommandName="Export" OnClientClick="Export(this, event); return false;" /> 
                     </span> 
                </div> 

And the methods to my codebehind:
private void WriteCalendar(string data) 
        { 
            HttpResponse response = Page.Response; 
            response.Clear(); 
            response.Buffer = true
            response.ContentType = "text/calendar"
            response.ContentEncoding = Encoding.UTF8; 
            response.Charset = "utf-8"
            response.AddHeader("Content-Disposition", "attachment;filename=\"RadSchedulerExport.ics\""); 
            response.Write(data); 
            response.End(); 
        } 
 
        protected void RadScheduler1_AppointmentCommand(object sender, AppointmentCommandEventArgs e) 
        { 
            if (e.CommandName == "Export") 
            { 
                WriteCalendar(RadScheduler.ExportToICalendar(e.Container.Appointment)); 
            } 
        }  

the button shows up, however when I click it I get:

"Microsoft JScript runtime error: Object expected" And it highlights the "Export(this, event); return false;" in here:
<input type="image" name="MasterCalendar1$RadScheduler1$ctl138$Button1" id="MasterCalendar1_RadScheduler1_ctl138_Button1" src="Outlook.gif" alt="Export to iCalendar" onclick="Export(this, event); return false;" style="border-width:0px;" /> 

I'm presuming this is because the Export() method hasn't been written in the .ascx as in the demo on the telerik site, however the instructions I was following do not mention this as necessary.

If this is the necessary code block:
<telerik:RadCodeBlock runat="server"
 
        <script type="text/javascript"
            function Export(sender, e) 
            { 
                $find("<%= RadAjaxManager1.ClientID %>").__doPostBack(sender.name, ""); 
            } 
        </script> 
 
    </telerik:RadCodeBlock> 

How do I change it to use it without the AjaxManager, I had to remove the AjaxManager to allow the calendar to work inside of sitefinity.






6 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 17 Sep 2009, 12:02 PM
Hello Jon,

Downloading files requires a real postback. This demo uses RadAjaxManager to ajaxify RadScheduler, so we need  to cause a real postback by handling the client click of the export button like this: 

function Export(sender, e)  
            {  
                $find("<%= RadAjaxManager1.ClientID %>").__doPostBack(sender.name, "");  
            } 

If you have to remove RadAjaxManager, then you no longer need the above approach. Simply remove the above function and the OnClientClick hook for the export button:
OnClientClick="Export(this, event); return false;"

After this change, the export functionality will still be preserved.


Regards,
Peter
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Kyle Jones
Top achievements
Rank 1
answered on 22 Sep 2009, 10:30 PM
How would you go about Accessing the RadAjaxManager when it is on a Master Page.  I tried many different ways to call the manager and nothing has worked for far.  I can't just take the Manager off the master page and put it in here so that the code works either cause I have 10 other pages that link to the Master Page and all of them are linking to the Manager via there code behind.
0
Peter
Telerik team
answered on 24 Sep 2009, 02:01 PM
Hi Kyle,

Add an AJAX Manager Proxy to your source page and use it the same way you would use RadAjaxManager.


All the best,
Peter
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Chris Phelps
Top achievements
Rank 1
answered on 03 Jun 2011, 02:57 AM
I have everything setup like the example, including the export function.  I have 4 appointments on my calendar.  Somehow, only 1 of those appointments will trigger the Sub RadScheduler1_AppointmentCommand.  I put a breakpoint on the line "If e.CommandName = "Export" (shown below) and it's only getting hit on one of the four appointments.  Each appointment does cause a postback though.



 

 

Protected Sub RadScheduler1_AppointmentCommand(ByVal sender As Object, ByVal e As AppointmentCommandEventArgs) Handles RadScheduler1.AppointmentCommand

 

 

 

 

If e.CommandName = "Export" Then

 

 

 

Dim aptStart As DateTime = DateTime.SpecifyKind(e.Container.Appointment.Start, DateTimeKind.Utc)

 

 

 

 

Dim currentOffset As TimeSpan = TimeZone.CurrentTimeZone.GetUtcOffset(aptStart)

 

 

WriteCalendar(

 

RadScheduler.ExportToICalendar(e.Container.Appointment, currentOffset))

 

 

 

 

End If

 

 

 

End Sub

 

0
Chris Phelps
Top achievements
Rank 1
answered on 04 Jun 2011, 01:50 AM
Please cancel my question above, I figured out that if you disable the ability to edit the appointment, if will not fire the AppointmentCommand sub routine.  I wish I could still have the ability to export the appointment, even when the e.appointment.allowedit is set to false.
0
Peter
Telerik team
answered on 08 Jun 2011, 01:57 PM
Hello Chris Phelps,

I tested setting AllowEdit=False with the online iCal export demo, but AppointmentCommand still fired and I was able to export the appointment successfully.

http://demos.telerik.com/aspnet-ajax/scheduler/examples/export/defaultcs.aspx

protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e)
      {
          e.Appointment.AllowEdit = false;
      }


Regards,
Peter
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Scheduler
Asked by
Jon Ingersoll
Top achievements
Rank 1
Answers by
Peter
Telerik team
Kyle Jones
Top achievements
Rank 1
Chris Phelps
Top achievements
Rank 1
Share this question
or