Click here to Skip to main content
15,122,559 members
Articles / Web Development / HTML
Alternative
Tip/Trick
Posted 27 Oct 2011

Stats

5.3K views

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
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)

Share

About the Author

rj45
Software Developer (Senior)
Canada Canada
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --