Javascript Error When Exporting to iCalendar

7 posts, 0 answers
  1. Jon Ingersoll
    Jon Ingersoll avatar
    12 posts
    Member since:
    May 2009

    Posted 14 Sep 2009 Link to this post

    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.






  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 17 Sep 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kyle Jones
    Kyle Jones avatar
    30 posts
    Member since:
    Jul 2009

    Posted 22 Sep 2009 Link to this post

    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.
  5. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 24 Sep 2009 Link to this post

    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.
  6. Chris Phelps
    Chris Phelps avatar
    10 posts
    Member since:
    Jan 2010

    Posted 02 Jun 2011 Link to this post

    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

     

  7. Chris Phelps
    Chris Phelps avatar
    10 posts
    Member since:
    Jan 2010

    Posted 03 Jun 2011 Link to this post

    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.
  8. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 08 Jun 2011 Link to this post

    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.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017