這是網友在
藍色小鋪發問的內容,版主
hunterpo給了一段很棒的範例程式碼,但C#的語法,我實在「沒法Do(台)」,所以就自己動手轉Code一下,貼在這裡留個記錄。
Default.aspx
01 | >form id= "form1" runat= "server" > |
03 | <asp:panel id= "Panel1" runat= "server" > |
05 | <asp:button id= "Button1" runat= "server" text= "Button" /> |
07 | <div id= "div1" runat= "server" > |
09 | <asp:button id= "Button2" runat= "server" text= "Button" /> |
11 | <asp:literal id= "Literal1" runat= "server" >>/asp:literal> |
Default.aspx.vb
需要先「Imports System.IO」命名;
05 | Private Function GetHtmlText( ByVal control As Control) As String |
06 | Dim sw As New StringWriter |
07 | Dim hw As New HtmlTextWriter(sw) |
09 | control.RenderControl(hw) |
15 | Public Overrides Sub VerifyRenderingInServerForm( ByVal control As System.Web.UI.Control) |
20 | Protected Sub Page_PreInit( ByVal sender As Object , ByVal e As System.EventArgs) Handles Me .PreInit |
21 | EnableEventValidation = False |
24 | Protected Sub Page_Load( ByVal sender As Object , ByVal e As System.EventArgs) Handles Me .Load |
25 | Dim p As String = GetHtmlText(Panel1) |
26 | Dim d = GetHtmlText(div1) |
28 | Literal1.Text = "Panel:" & Server.HtmlEncode(p) & " |
29 | " & " div:" & Server.HtmlEncode(d) |
重點在GetHtmlText方法上,System.IO是我比較少用的類別,順便學習一下。
沒有留言:
張貼留言
感謝您的留言,如果我的文章你喜歡或對你有幫助,按個「讚」或「分享」它,我會很高興的。