將ASP.NET Control轉(zhuǎn)換為String
2024-07-10 12:57:11
供稿:網(wǎng)友
下面的類(lèi)可以實(shí)現(xiàn)將asp.net的control(包括aspx頁(yè)面)轉(zhuǎn)換成string字符串,可以用于:
用郵件發(fā)送asp.net的內(nèi)容
用xslt轉(zhuǎn)換頁(yè)面的輸出
aspx頁(yè)面的全局字符串的使用
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代碼
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
中國(guó)最大的web開(kāi)發(fā)資源網(wǎng)站及技術(shù)社區(qū),