我想在控件加载后呈现前,取到该控件的html流,然后根据条件修改该控件的html流,然后再呈现到页面去,如何做?
最好有代码,谢谢!!!!

解决方案 »

  1.   

    可以重写Render方法.取消默认的Render实现.请把场景描述更清楚些. 是封装控件吗?
      

  2.   

    在Render方法里面如何取到完整的html字符流,加以处理?谢谢
      

  3.   

        public class Render
        {
            public static string RenderControl(System.Web.UI.Control control)
            {
                StringBuilder result = new StringBuilder(1024);
                control.RenderControl(new HtmlTextWriter(new StringWriter(result)));
                return result.ToString();
            }
            public static string RenderControl(System.Web.UI.TemplateControl control)
            {
                StringBuilder result = new StringBuilder(1024);
                control.RenderControl(new HtmlTextWriter(new StringWriter(result)));
                return result.ToString();
            }
            public static string RenderPage(string pageLocation)
            {
                System.Web.HttpContext context = System.Web.HttpContext.Current;
                StringBuilder result = new StringBuilder(1024);
                context.Server.Execute(pageLocation,
                new HtmlTextWriter(new StringWriter(result)));
                return result.ToString();
            }
        } 
    不知道谁写的
      

  4.   

    我不仅要取到html,还修改后写回去,如何搞?
      

  5.   

    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using System.Web.UI.HtmlControls; 
    using System.IO; /// <summary> 
    /// static_htm 的摘要说明 
    /// </summary> 
    ///     public abstract class static_htm : System.Web.UI.Page 
        { 
          protected override void Render(HtmlTextWriter writer)     {         StringWriter sw = new StringWriter();         HtmlTextWriter htmlw = new HtmlTextWriter(sw);         //调用Render方法,把页面内容输出到StringWriter中         base.Render(htmlw);         htmlw.Flush();         htmlw.Close();         //获得页面内容         string pageContent = sw.ToString();                     string path = Server.MapPath("~/CacheFile/");         if (!Directory.Exists(path))         {             Directory.CreateDirectory(path);         } 
            string pageUrl = StaticFileCacheModule.GetFileName(HttpContext.Current);         if(!File.Exists(pageUrl))         {   //把页面内容保存到静态文件中             using (StreamWriter stringWriter = File.CreateText(path + pageUrl))             {                 stringWriter.Write(pageContent); ;             }         } 
            //将页面内容输出到浏览器         Response.Write(pageContent);     } 

      

  6.   

    StringWriter sw = new StringWriter();         HtmlTextWriter htmlw = new HtmlTextWriter(sw);         //调用Render方法,把页面内容输出到StringWriter中         base.Render(htmlw); 
    ====================================================
    获取html流