Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / HTML

Parse out controls from your html page.

5.00/5 (1 vote)
27 Oct 2011CPOL 6.2K  
You can simplify this by doing the following:/// /// Render/// /// protected override void Render(HtmlTextWriter writer){ if (Session[ExcelExport] != null && bool.Parse(Session[ExcelExport].ToString())) { ...
You can simplify this by doing the following:

XML
/// <summary>
/// Render
/// </summary>
/// <param name="writer"></param>
protected override void Render(HtmlTextWriter writer)
{
    if (Session[ExcelExport] != null && bool.Parse(Session[ExcelExport].ToString()))
    {
        List<Control> flatList = Utilities.FindControls(this);

        foreach (Control item in flatList)
        {
            if (item.GetType() == typeof(Image))
            {
                item.Visible = false;
            }
            if (item.GetType() == typeof(System.Web.UI.DataVisualization.Charting.Chart))
            {
                item.Visible = false;
            }
        }
        StringBuilder html = null;
        using (System.IO.StringWriter stringWrite = new System.IO.StringWriter())
        {
            using (RewriteLinkHtmlTextWriter htmlWrite = new RewriteLinkHtmlTextWriter(stringWrite))
            {
                base.Render(htmlWrite);
                html = new StringBuilder(stringWrite.ToString());
            }
        }
        DownloadExcel(html.ToString());
    }
    else
    {
        base.Render(writer);
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)