Click here to Skip to main content
12,451,455 members (47,642 online)
Click here to Skip to main content
Add your own
alternative version

Stats

2.7K views
Posted

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

You may also be interested in...

Pro
Pro

Comments and Discussions

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