您好,登錄后才能下訂單哦!
這篇文章主要講解了“ASP.net Control到String的轉(zhuǎn)換方法是什么”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“ASP.net Control到String的轉(zhuǎn)換方法是什么”吧!
下面的類可以實(shí)現(xiàn)將ASP.net Control(包括aspx頁(yè)面)轉(zhuǎn)換成String字符串,可以用于:
◆用郵件發(fā)送ASP.NET的內(nèi)容
◆用XSLT轉(zhuǎn)換頁(yè)面的輸出
◆ASPX頁(yè)面的全局字符串的使用
將ASP.net Control轉(zhuǎn)換成String字符串的C#代碼
using System; using System.IO; using System.Text; using System.< a href="http://dev.21tx.com/web/" target="_blank">Web< /a>; 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 Rend< a href="http://dev.21tx.com/corp/solution/erp/" target="_blank">ERP< /a>age(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(); } }
將ASP.net Control轉(zhuǎn)換成String字符串的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
感謝各位的閱讀,以上就是“ASP.net Control到String的轉(zhuǎn)換方法是什么”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)ASP.net Control到String的轉(zhuǎn)換方法是什么這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。