ASP.netControl到String的转换方法

下面的类可以实现将ASP.net Control(包括aspx页面)转换成String字符串,可以用于:

◆用邮件发送ASP.NET的内容

◆用XSLT转换页面的输出

◆ASPX页面的全局字符串的使用

将ASP.net Control转换成String字符串的C#代码

 
 
 
  1. using System; 
  2. using System.IO; 
  3. using System.Text; 
  4. using System.< a href="http://dev.21tx.com/web/" target="_blank">Web< /a>; 
  5. using System.Web.UI; 
  6.  
  7. public class Render 
  8.  public static string RenderControl(System.Web.UI.Control control) 
  9.  { 
  10.  StringBuilder result = new StringBuilder(1024); 
  11.  control.RenderControl(new HtmlTextWriter(new StringWriter(result))); 
  12.  return result.ToString(); 
  13.  } 
  14.  public static string RenderControl(System.Web.UI.TemplateControl control) 
  15.  { 
  16.  StringBuilder result = new StringBuilder(1024); 
  17.  control.RenderControl(new HtmlTextWriter(new StringWriter(result))); 
  18.  return result.ToString(); 
  19.  } 
  20.  public static string Rend< a href="http://dev.21tx.com/corp/solution/erp/" target="_blank">ERP< /a>age(string pageLocation) 
  21.  { 
  22.  System.Web.HttpContext context = System.Web.HttpContext.Current; 
  23.  StringBuilder result = new StringBuilder(1024); 
  24.  context.Server.Execute(pageLocation, 
  25.  new HtmlTextWriter(new StringWriter(result))); 
  26.  return result.ToString(); 
  27.  } 
  28. }

将ASP.net Control转换成String字符串的VB.NET代码

 
 
 
  1. Imports System 
  2. Imports System.IO 
  3. Imports System.Text 
  4. Imports System.Web 
  5. Imports System.Web.UI 
  6.  
  7. Public Class Render 
  8.  Public Shared Function RenderControl(ByVal control As System.Web.UI.Control)_ 
  9.  As String 
  10.  Dim result As StringBuilder = New StringBuilder(1024) 
  11.  control.RenderControl(New HtmlTextWriter(New StringWriter(result))) 
  12.  Return result.ToString() 
  13.  End Function 
  14.  Public Shared Function RenderControl(ByVal control As System.Web.UI.TemplateControl)_ 
  15.  As String 
  16.  Dim result As StringBuilder = New StringBuilder(1024) 
  17.  control.RenderControl(New HtmlTextWriter(New StringWriter(result))) 
  18.  Return result.ToString() 
  19.  End Function 
  20.  Public Shared Function RenderPage(ByVal pageLocation As StringAs String 
  21.  Dim context As System.Web.HttpContext = System.Web.HttpContext.Current 
  22.  Dim result As StringBuilder = New StringBuilder(1024) 
  23.  context.Server.Execute(pageLocation, _ 
  24.  New HtmlTextWriter(New StringWriter(result))) 
  25.  Return result.ToString() 
  26.  End Function 
  27. End Class 

分享名称:ASP.netControl到String的转换方法
URL网址:http://www.shufengxianlan.com/qtweb/news16/427866.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联