0

I have written the below code to send the Gridview and Chart Image in email body message (not as an attachment) using C# ASP.Net.

    StringBuilder sb = new StringBuilder();
    string MailSturcture;

    using (System.IO.StringWriter sw = new StringWriter())
    {
        using (HtmlTextWriter hw = new HtmlTextWriter(sw))
        {
            gvDaySummary.RenderControl(hw);
            hw.WriteBreak();
            BarChart1.RenderControl(hw);

            System.IO.StringReader sr = new StringReader(sw.ToString());

            MailMessage mail = new MailMessage();
            mail.From = new MailAddress("noreply@xxx.com", "aura");
            mail.To.Add("abc@xxx.com");

            mail.Subject = "Daily Payment Summary";
            mail.IsBodyHtml = true;
            sb.AppendFormat(sw.ToString());

            MailSturcture = sb.ToString();
            mail.Body = MailSturcture;

            System.Net.Mail.SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtpout.secureserver.net";
            smtp.Port = 80;
            System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
            NetworkCred.UserName = "abc@xxx.com";
            NetworkCred.Password = "xxx";
            smtp.UseDefaultCredentials = true;
            smtp.Credentials = NetworkCred;
            smtp.EnableSsl = false;
            smtp.Send(mail);
        }
    }

    public override void VerifyRenderingInServerForm(System.Web.UI.Control control)
    {
        /* Verifies that the control is rendered */
    }

If I remove the BarChart1 control then Gridview shows in the mail message perfectly but while I add, BarChart1 throws the below error.

Script control 'BarChart1' is not a registered script control. Script controls must be registered using RegisterScriptControl() before calling RegisterScriptDescriptors().
Parameter name: scriptControl

Can anyone please clarify me exactly whats the error.

Arun
  • 728
  • 4
  • 16
  • 30
  • [radix](http://www.telerik.com/forums/script-controls-must-be-registered-using-registerscriptcontrol-before-calling-registerscriptdescriptors) see if this helps with your issue. – vipersassassin Feb 15 '17 at 18:13
  • @vipersassassin I m not using the telerik control – Arun Feb 15 '17 at 18:15
  • The top line of code is missing Can you please show the name of the method that you are using? I'm specifically looking for the ASP.net page life cycle method that calls this code – Nandun Feb 15 '17 at 21:07
  • @Nandun protected void SendMailIB_Click(object sender, ImageClickEventArgs e) – Arun Feb 20 '17 at 19:49
  • Check if you are hiding BarChart1 at any stage before the Click event. for e.g. during pre init, init, pre load, page load etc. – Nandun Feb 22 '17 at 14:20

0 Answers0