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

RadGrid RawHTML

0 Answers 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hiren
Top achievements
Rank 1
Hiren asked on 13 Jan 2012, 03:59 PM
Hi,

I have a requirement where we have two buttons 
First Button for export the Grid to PDF/Excel. 
second button for send email (custom email form shown in RadWindow)

For Export To PDF we are using custom PDF Code where we have used abcpdf7.0, (for Proper CSS & Word wraping) for excel we are using radgrid..MasterTableView.ExportToExcel()

We have used PdfExporting event as we want to suppress the export pdf for telerik & show our own pdf that we are generating.
protected void rgdEthnicityReport_PdfExporting(object sender, Telerik.Web.UI.GridPdfExportingArgs e)
       {
           if (isPdfExport)
           {
               GeneratePdfDocument(e.RawHTML);
           }
           else
           {
               Session["HTMLContent"] = e.RawHTML;
           }
             
       }

GeneratePDFDocument is custom method that we have written. Below is the code
private void GeneratePdfDocument(string htmlContent)
        {
            try
            {
                this.PDF = new Doc();
                PDF.Rect.Inset(10, 50);
                this.PDF.HtmlOptions.Timeout = 600000;
                this.PDF.HtmlOptions.RetryCount = 2;
                int pdfID;
                PDF.TopDown = true;
                pdfID = this.PDF.AddImageHtml(htmlContent);
  
                while (true)
                {
                    if (this.PDF.Chainable(pdfID) == false)
                        break;
                    this.PDF.Page = PDF.AddPage();
  
                    pdfID = this.PDF.AddImageToChain(pdfID);
                }
  
                object pdfObject = this.PDF.GetData();
  
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ContentType = "application/pdf";
                HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + "Ethnicity Summary Report" + ".pdf");
                HttpContext.Current.Response.ContentType = "application/octet-stream";
                HttpContext.Current.Response.BinaryWrite((byte[])pdfObject);
                this.PDF.Clear();
                HttpContext.Current.Response.End();
            }
            catch (EHRExceptions ex)
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "excAlert", "$(document).ready(function(){jAlert('" + Utility.ContentFetcher.GetValidationMessage("GREX_1", BOL.Classes.EHRSessions.Culture) + "');});", true);
                Utility.MailSender.ExceptionLogger(log, ex.ErrorCode, BOL.Classes.EHRSessions.ClinicId, BOL.Classes.EHRSessions.UserId, ex.Message, ex.GetBaseException());
            }
}


On second button "Send Email" I need only RawHTMl and then call RadWindow to show our custom form for sending email.
To do this we have kept a Flag isPdfExport so that it stores the RawHtml in session.

On send Email Button Click below code is used.
protected void rbtnSendMail_Click(object sender, EventArgs e)
        {
            if (NeedRedirection || WasSessionEnd()) return;
            try
            {
                isPdfExport = false;
                this.rgdEthnicityReport.MasterTableView.ExportToPdf();
                string Intext = "false";
                string letterName = "Ethnicity Summary Report";
  
                RadWindow1.NavigateUrl = "~/Patient/Management/ReportEmailing.aspx";
                RadWindow1.NavigateUrl += "?InText=" + Intext + "&LetterName=" + letterName + "&EmailCategory=Report";
                RadWindow1.Title = "Ethnicity Summary Report";
                RadWindow1.Visible = true;
                RadWindow1.VisibleOnPageLoad = true;
  
            }
            catch (EHRExceptions ex)
            {
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "excAlert", "$(document).ready(function(){jAlert('" + Utility.ContentFetcher.GetValidationMessage("GREX_1", BOL.Classes.EHRSessions.Culture) + "');});", true);
                Utility.MailSender.ExceptionLogger(log, ex.ErrorCode, BOL.Classes.EHRSessions.ClinicId, BOL.Classes.EHRSessions.UserId, ex.Message, ex.GetBaseException());
            }
}


We are callingthis.rgdEthnicityReport.MasterTableView.ExportToPdf(); so that pdfexporting event is called and we get RawHtml in the session (due to isPDFExport set to false. I have issue over here, It is not showing our Window for sending email & showing the pdf exported by telerik. I want to suppress this & getonly RawHtml & then execute our code for sending email by showing radwindow. We also tried moving code from send email to pdfexporting block but same issue.

Please suggest how to achieve this.

Thanks.

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Hiren
Top achievements
Rank 1
Share this question
or