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

printing from within an ajax panel causes javascript error

1 Answer 14 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 30 Dec 2011, 06:13 AM
Hello,

I have a radrid with one column setup for printing the object associated with the ID of the row.  Works great unless I ajaxify the grid either wrapping with an AJAX panel or using an ajax manager on the page then I get a javascript error on postback wchihc makes sense because the ajax manager or panel will be trying to interpret the response.  How to I bypass the ajax panel for this one behaviour and have the browser rather than the ajax manager respond to the new contect header information?
protected void radGridAll_ItemCommand(Object sender, GridCommandEventArgs e)
        {
            if (e.CommandName != "Print" ) return;
  
            Guid id = Guid.Parse(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"].ToString());
  
            //lblMessage.Text = string.Empty;
  
            switch (e.CommandName)
            {
  
                case "Print":
  
                    //string args = Request.QueryString["ApplicationID"];
  
                    NMotionServer.ApplicationLead _application = NMotionServer.ApplicationLeadService.GetByID(id);
  
                    if (_application.LeadStatusID == (int)enumLeadStatus.Fresh || _application.LeadStatusID == (int)enumLeadStatus.Viewed)
                    {
                        AppHistory _leadStatusEvent = new AppHistory() { ApplicationLeadID = _application.ID, EventTypeID = 2, ForeignKeyID = (int)enumLeadStatus.Printed, Timestamp = DateTime.Now, UserProfileID = ((UserProfile)Session["_userProfile"]).ID };
                        AppHistoryService.Save(_leadStatusEvent);
                        _application.LeadStatusID = (int)enumLeadStatus.Printed;
                        ApplicationLeadService.Save(_application);
                    }
  
                    //RptApplication _applicationReport = new RptApplication((DealerLinkServer.SalesForceWebReference.SforceService)Session["SalesForceBinding"], args);
  
                    RptApplication _applicationReport = new RptApplication(id.ToString());
                    ReportProcessor _processor = new ReportProcessor();
                    RenderingResult result = _processor.RenderReport("PDF", _applicationReport, null);
                    string fileName = "NMotion_Lead_" + _application.ApplicantNameLast2First.Replace(" ", "_").Replace(",","_").Replace("'", "_") + "_" + _application.DateOfApplication.Year + _application.DateOfApplication.Month + _application.DateOfApplication.Day + ".pdf";
  
                    Response.Clear();
                    Response.ContentType = result.MimeType;
                    Response.Cache.SetCacheability(HttpCacheability.Private);
                    Response.Expires = -1;
                    Response.Buffer = true;
  
                    Response.AddHeader("Content-Disposition", string.Format("{0};FileName=\"{1}\"", "attachment", fileName));
                    Response.BinaryWrite(result.DocumentBytes);
                    Response.End();
  
                    break;
            }
        }

Thanks
Jonathan

1 Answer, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 03 Jan 2012, 02:43 PM
Hi Jonathan,

Editing the Response Headers with ajax request is not supported. Your application need to fully reload the page in order for your scenario to work.

All the best,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Ajax
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
Share this question
or