首页  ·  知识 ·  云计算
ASP.NETControl转换为String
佚名  ddvip  综合  编辑:dezai  图片来源:网络
下面的类可以实现将ASP.net的Control(包括aspx页面)转换成String字符串,可以用于:   用邮件发送ASP.NET的内容   用XSLT转换页面的

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

  用邮件发送ASP.NET的内容

  用XSLT转换页面的输出

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

  C#代码

 using System;
 using System.IO;
 using System.Text;
 using System.http://dev.21tx.com/web/" target="_blank">Web;
 using System.Web.UI;
 
 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 Rendhttp://dev.21tx.com/corp/solution/erp/" target="_blank">ERPage(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();
  }
 }

  VB.NET代码

 Imports System
 Imports System.IO
 Imports System.Text
 Imports System.Web
 Imports System.Web.UI
 
 Public Class Render
  Public Shared Function RenderControl(ByVal control As System.Web.UI.Control)_
  As String
  Dim result As StringBuilder = New StringBuilder(1024)
  control.RenderControl(New HtmlTextWriter(New StringWriter(result)))
  Return result.ToString()
  End Function
  Public Shared Function RenderControl(ByVal control As System.Web.UI.TemplateControl)_
  As String
  Dim result As StringBuilder = New StringBuilder(1024)
  control.RenderControl(New HtmlTextWriter(New StringWriter(result)))
  Return result.ToString()
  End Function
  Public Shared Function RenderPage(ByVal pageLocation As String) As String
  Dim context As System.Web.HttpContext = System.Web.HttpContext.Current
  Dim result As StringBuilder = New StringBuilder(1024)
  context.Server.Execute(pageLocation, _
  New HtmlTextWriter(New StringWriter(result)))
  Return result.ToString()
  End Function
 End Class

本文作者:佚名 来源:ddvip
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读