Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Parse out controls from your html page.

, 27 Oct 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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:
 
/// <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)

Share

About the Author

rj45
Software Developer (Senior)
Canada Canada
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141220.1 | Last Updated 27 Oct 2011
Article Copyright 2011 by rj45
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid