zoukankan      html  css  js  c++  java
  • ASP.NET 中如何对生成的 HTML 内容流进行控制

    1. 转自:blog.csdn.net/net_lover/archive/2010/02/25/5324455.aspx

    2. <%@ Page Language="C#" %>  
    3. <%@ Import Namespace="System.IO" %>  
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    5. <script runat="server">  
    6.   protected override void Render(HtmlTextWriter writer)  
    7.   {  
    8.     string content = string.Empty;  
    9.     StringWriter stringWriter = new StringWriter();  
    10.     HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);  
    11.     try  
    12.     {  
    13.       // 将当前页面的内容呈现到临时的 HtmlTextWriter 对象中  
    14.       base.Render(htmlWriter);  
    15.       htmlWriter.Close();  
    16.       // 得到当前页面的全部内容  
    17.       content = stringWriter.ToString();  
    18.       // 替换页面中的部分内容  
    19.       string newContent = content.Replace("[mxh]""孟宪会");  
    20.       // 将新页面的内容显示出来  
    21.       writer.Write(newContent);  
    22.     }  
    23.     catch { }  
    24.     finally  
    25.     {  
    26.       stringWriter.Dispose();  
    27.       htmlWriter.Close();  
    28.       htmlWriter.Dispose();  
    29.     }  
    30.   }  
    31. </script>  
    32. <html xmlns="http://www.w3.org/1999/xhtml">  
    33. <head id="Head1" runat="server">  
    34.   <title>孟宪会之替换页面呈现内容测试</title>  
    35. </head>  
    36. <body>  
    37.   <form id="form1" runat="server">  
    38.   [mxh]  
    39.   </form>  
    40. </body>  
    41. </html>  
  • 相关阅读:
    Restart
    Tired
    Money,Right or Nation?
    End
    Cooperation
    【kooboo】代码块
    [kooboo]创建站点过程
    [kooboo] 使用 SQL Server 进行持久化 方法
    两种实现模式,还是选择2,少一层继承。
    读取进程内所有用户Session
  • 原文地址:https://www.cnblogs.com/iwaitu/p/1712298.html
Copyright © 2011-2022 走看看