All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
将ASP.NET,Control转换为String_[Asp.Net教程]

Writer: delv Article type: Programming skills(编程技巧) Time: 2014/1/16 9:33:00 Browse times: 376 Comment times: 0

将ASP.NET,Control转换为String_[Asp.Net教程]


Head photo

Go homepage
Upload pictures
Write articles

将ASP.NET Control转换为String_[Asp.Net教程]

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

1.用邮件发送ASP.NET的内容
2.用XSLT转换页面的输出
3.ASPX页面的全局字符串的使用

C#代码
复制C#代码保存代码using System;
using System.IO;
using System.Text;
using System.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 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();
}
}
VB.NET代码

复制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

来源:阿良.NET





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.