如果我們想要在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姍舞之間的極度凝聚】,感恩大家的配合。
- 如果您覺得此篇對您或者對大家有幫助,敬請按一下【推薦】,感恩!! ^_^
推到 Plurk!
DotBlogs Tags:
ASP.NET