Click here to Skip to main content
15,867,686 members
Articles / Web Development / HTML
Alternative
Tip/Trick

Parse out controls from your html page.

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
27 Oct 2011CPOL 6K  
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)


Written By
Software Developer (Senior)
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --