在CodeFile中取得控件将输出Clinet端的HTML内容
如果我们想要在CodeFile中取得某控件运行后将会送出的HTML内容可以透过以下的Function来处理。
Public Function GetHTML(ByVal objWebControl As WebControl) As String
Try
'以 StringWriter 取得HTML
Dim w As New System.IO.StringWriter
Dim a As New HtmlTextWriter(w)
objWebControl.RenderControl(a)
Return w.ToString
Catch ex As Exception
Throw
End Try
End Function
Public Function GetHTML(ByVal objHtmlControl As HtmlControl) As String
Try
'以 StringWriter 取得HTML
Dim w As New System.IO.StringWriter
Dim a As New HtmlTextWriter(w)
objHtmlControl.RenderControl(a)
Return w.ToString
Catch ex As Exception
Throw
End Try
End Function
小喵把这一段内容放在PageBase里面,让所有页面可以简单的调用,PageBase的使用方式请看以下这篇:
ASP.NET中如何每一页调用公用Function(PageBase)
以上这个方式,再使用GridView的时候会发生状况,解决方式请参考以下这篇:
解决GridView使用RenderControl取得HTML出现的问题
以下是签名:
- 欢迎转贴本站的文章,不过请在贴文主旨上加上【转贴】,并在文章中附上本篇的超链接与站名【topcat姗舞之间的极度凝聚】,感恩大家的配合。
- 小喵大部分的文章会以小喵熟悉的语言VB.NET撰写,如果您需要C#的Code,也许您可以试着用线上的工具进行转换,这里提供几个参考
- http://converter.telerik.com/
- http://www.carlosag.net/tools/codetranslator/
- http://www.developerfusion.com/tools/convert/vb-to-csharp/
|
topcat |
原文:大专栏 在CodeFile中取得控件将输出Clinet端的HTML内容