+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / iCalander download on ajax call

iCalander download on ajax call

1 posts, 0 answered
  1. Tarun
    Tarun avatar
    81 posts
    Registered:
    14 Jan 2009
    07 Feb 2011
    Link to this post
    Hi,

    I am creating an event calander in a grid and trying to download but the download is not working on ajax call and throw below error. Below you can find used code 

    Ckeck link for live result:
    http://sf.sacitportal.com/Events.aspx

    Uncaught Sys.WebForms.PageRequestManagerParserErrorException: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
     
    Details: Error parsing near 'BEGIN:VCALENDAR
     
    VER'.
    Sys$WebForms$PageRequestManager$_endPostBackScriptResource.axd:513
    Sys$WebForms$PageRequestManager$_parseDeltaScriptResource.axd:1021
    Sys$WebForms$PageRequestManager$_onFormSubmitCompletedScriptResource.axd:903
    (anonymous function)ScriptResource.axd:47
    (anonymous function)ScriptResource.axd:2399
    Sys$Net$WebRequest$completedScriptResource.axd:5103
    Sys$Net$XMLHttpExecutor._onReadyStateChange

    Code :

    protected void catGrid_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "ical")
            {
     
                //HttpResponse response = context.Response;
                //HttpRequest request = context.Request;
                try
                {
                    Guid EventID = new Guid(e.CommandArgument.ToString());
                    Response.BufferOutput = true;
                    Response.ContentType = "text/binary";
                    Response.AddHeader("content-disposition", "inline; filename=event.ics");
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    string domain =  Request.ServerVariables["SERVER_NAME"];
                    writeCalEntry(EventID, Response.Output, domain);
                    //Response.End();
                }
                catch(Exception es)
                {
                    Response.Write("Error: Invalid Event");
                }
     
     
    }
     
     
      public void writeCalEntry(Guid EventID,System.IO.TextWriter output, String domain)
        {
            Telerik.Events.EventsManager eventsManager = new Telerik.Events.EventsManager("Events");
            Telerik.Events.IEvent selectedEvent;
     
            //IList listOfAllEvents = eventsManager.GetEvents();
            if (1 > 0)
            {
                try
                {
                    ContentManager m = new ContentManager("Events");
                    IContent content = m.GetContent(EventID);
                    selectedEvent = eventsManager.GetEvent(EventID);
     
     
                    selectedEvent = eventsManager.GetEvent(EventID);
     
                    System.DateTime starttime, endtime;
                    string title, description, location, url;
     
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    object o;
     
                    starttime = (DateTime)content.GetMetaData("Event_Start"); ;
                    endtime = (DateTime)content.GetMetaData("Event_End");
                    title = (string)content.GetMetaData("Title").ToString(); ;
                    location = (string)content.GetMetaData("City").ToString();
     
                    o = content.Content;
                    if (o != DBNull.Value && (string)o != "")
                    {
                        sb.AppendLine(StripHTML((string)o));
                    }
                    sb.AppendLine();
     
     
                    System.Text.UnicodeEncoding uc = new System.Text.UnicodeEncoding();
                    description = sb.ToString();
                    output.WriteLine("BEGIN:VCALENDAR");
                    output.WriteLine("VERSION:2.0");
                    output.WriteLine("METHOD:PUBLISH");
                    output.WriteLine("BEGIN:VEVENT");
                    output.WriteLine("UID:" + Guid.NewGuid().ToString());
                    output.WriteLine("DTSTAMP:" + DateTime.Now.ToUniversalTime().ToString("yyyyMMddTHHmmss") + "Z");
                    output.WriteLine(EncodeProperty("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:", description));
                    output.WriteLine("DTEND:" + endtime.ToUniversalTime().ToString("yyyyMMddTHHmmss") + "Z");
                    if (!(location == null))
                    {
                        output.WriteLine(EncodeProperty("LOCATION;ENCODING=QUOTED-PRINTABLE:", location));
                    }
                    output.WriteLine("PRIORITY:0");
                    output.WriteLine("DTSTART:" + starttime.ToUniversalTime().ToString("yyyyMMddTHHmmss") + "Z");
                    output.WriteLine("STATUS:NEEDS ACTION");
                    output.WriteLine(EncodeProperty("SUMMARY;ENCODING=QUOTED-PRINTABLE:", title));
                    output.WriteLine("END:VEVENT");
                    output.WriteLine("END:VCALENDAR");
                   // Response.Write(output.ToString());
                }
                catch
                {
                }
            }
        }

    ascx Controrol :

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="CustomContentView.ascx.cs"
        Inherits="UserControls_CustomContentView" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Cms.Engine.WebControls" Assembly="Telerik.Cms.Engine" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Cms.Engine.WebControls.Admin" Assembly="Telerik.Cms.Engine" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Cms.Web.UI" Assembly="Telerik.Cms.Web.UI" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="cc2" Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" %>
    <%@ Register TagPrefix="cc2" Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls" %>
    <%@ Register TagPrefix="cc2" Namespace="Telerik.Libraries.WebControls" Assembly="Telerik.Libraries" %>
    <%@ Register TagPrefix="sfLib" Namespace="Telerik.Libraries.WebControls" Assembly="Telerik.Libraries" %>
    <%@ Register TagPrefix="sfLib" Namespace="Telerik.Cms.Engine.WebControls" Assembly="Telerik.Cms.Engine" %>
    <%@ Register TagPrefix="sfLib" Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls.Design" %>
    <%@ Register TagPrefix="sfLib" Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls.Design.Settings" %>
    <%@ Register TagPrefix="sfLib" Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls.Design.Selectors" %>
    <%@ Register TagPrefix="sfLib" Assembly="Telerik.Libraries" Namespace="Telerik.Libraries.WebControls.Admin" %>
    <%@ Register TagPrefix="sfWeb" Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" %>
    <%@ Register Assembly="Telerik.Search" Namespace="Telerik.Search.WebControls" TagPrefix="sfSrcBx" %>
    <%@ Register Assembly="InstantCommunity.Sitefinity.Controls" Namespace="InstantCommunity.Sitefinity.Controls"
        TagPrefix="InstantCommunity" %>
     
     
    <script type="text/javascript">
     
     
     
        function GetClearButton(sender, eventArgs) {
           // alert("d");
            
        }
    </script>
     
    <telerik:RadAjaxLoadingPanel runat="server" ID="LoadingPanel1" Skin="Sitefinity">
    </telerik:RadAjaxLoadingPanel>
    <telerik:RadAjaxPanel runat="server" ID="AjaxPanel1">
        <asp:Panel ID="pnlContentMain" runat="server">
            <asp:Label ID="lblMessage" runat="server"></asp:Label><asp:Button ID="temp" Visible="false"
                runat="server" Text="Temp" />
            <table>
                <tr>
                    <td style="vertical-align: top;">
                        <table>
                            <tr>
                                <td>
                                    <table style="background: white; border: 1px solid #000011;" cellpadding="0" cellspacing="0">
                                        <tr>
                                            <td style="border-right: 0px;" valign="top">
                                                <telerik:RadTextBox ID="txtSearch" BorderWidth="0" Width="107" ClientEvents-OnKeyPress="GetClearButton"
                                                    EmptyMessage="Keywork search..." runat="server" Style="margin: 0px 0px 0px 0px;">
                                                </telerik:RadTextBox>
                                            </td>
                                            <td style="border-left: 0px;" valign="top">
                                                <div id="clearBtnDiv" runat="server" style="visibility: hidden; margin: 0px 0px 0px 0px;">
                                                    <a id="clearBtn" href="#" runat="server" style="background: white; border: 0px;">?</a>
                                                </div>
                                            </td>
                                            <td style="border-left: 0px;" valign="top">
                                                <asp:Button ID="btnGo" Text="GO" Style="border: 0px;" runat="server" />
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <telerik:RadDatePicker ID="calFrom" runat="server" Width="100px" AutoPostBack="false"
                                        DateInput-EmptyMessage="MinDate" MinDate="1/1/0001">
                                        <Calendar runat="server" ID="Calendar1">
                                            <SpecialDays>
                                                <telerik:RadCalendarDay Repeatable="Today" ItemStyle-CssClass="rcToday" />
                                            </SpecialDays>
                                        </Calendar>
                                    </telerik:RadDatePicker>
                                    <br />
                                    <telerik:RadDatePicker ID="calTo" runat="server" Width="100px" AutoPostBack="false"
                                        DateInput-EmptyMessage="MaxDate" MinDate="1/1/0001">
                                        <Calendar ID="Calendar2" runat="server">
                                            <SpecialDays>
                                                <telerik:RadCalendarDay Repeatable="Today" ItemStyle-CssClass="rcToday" />
                                            </SpecialDays>
                                        </Calendar>
                                    </telerik:RadDatePicker>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <telerik:RadComboBox ID="comboCustomCategory" AutoPostBack="true" runat="server">
                                    </telerik:RadComboBox>
                                    <%--                                                <InstantCommunity:CustomCategory ID="comboCustomCategory" runat="server" ></InstantCommunity:CustomCategory>
    --%>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td>
                        <%--            <asp:HyperLink ID="backLink" runat="server" Text="GoBack"></asp:HyperLink>
    --%>
                        <asp:Panel ID="sortDiv" runat="server">
                            <table>
                                <thead>
                                    <tr>
                                        <th scope="col">
                                            <asp:LinkButton ID="lnkName" runat="server" Text="Name" ToolTip="Sort" CommandName="Name"></asp:LinkButton>     
                                        </th>
                                        <th scope="col">
                                            <asp:LinkButton ID="lnkDateCreated" runat="server" Text="Date" ToolTip="Sort" CommandName="DateCreated"></asp:LinkButton>
                                        </th>
                                    </tr>
                                </thead>
                            </table>
                        </asp:Panel>
                        <div>
                            <telerik:RadGrid ID="catGrid" CellSpacing="0" GridLines="None" BorderWidth="0" Width="550"
                                runat="server" ShowHeader="false" ShowFooter="false" AllowSorting="true" AutoGenerateColumns="false">
                                <MasterTableView>
                                    <Columns>
                                        <telerik:GridTemplateColumn>
                                            <ItemTemplate>
                                                <strong>
                                                <asp:HyperLink NavigateUrl='<%# Eval("Url")%>' ID="fullContent1" runat="server" Text='<%# Eval("Title")%>'></asp:HyperLink></strong><br />
                                                <asp:Label ID="lblSnippet" runat="server" Text='<%# Eval("Snippet") %>'></asp:Label><br />
                                                <asp:Literal ID="Literal2" Text='<%#Eval("Event_Start") %>' runat="server"></asp:Literal><br />
                                                <asp:Label  ID="Literal1" Text='<%#Eval("City") %>' Font-Bold="true" runat="server"></asp:Label>
                                                <asp:LinkButton ID="lnkCal"  runat="server" CommandArgument='<%# Eval("GUID") %>' CommandName="ical"><asp:Image ID="imgCal" ToolTip="Block your calander" ImageUrl="~/Images/icon-outlook.png" runat="server" /> </asp:LinkButton>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                    </Columns>
                                </MasterTableView>
                            </telerik:RadGrid>
                        </div>
                    </td>
                </tr>
            </table>
        </asp:Panel>
    </telerik:RadAjaxPanel>
    <asp:Repeater ID="repeater" runat="server" EnableViewState="False">
    </asp:Repeater>



    But the calander download does work on first postback (which is already  an issue and have posted on forums with the link http://www.sitefinity.com/devnet/forums/sitefinity-3-x/developing-with-sitefinity/ajax-on-content-view-control.aspx) after first postback ajax activated and download stop.
1 posts, 0 answered