熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

.NET 2.0中直接得到頁面HTML代碼

2022-06-13   來源: .NET編程 

  在ASPNET有時候需要對ASPNET生成的HTML代碼進行處理或者是保存成靜態文件ASPNET 提供了直接將請求保存成文件的方法HttpRequestSaveAs方法下面這個方法就是在ASPNET 中得到ASPNET生成的HTML代碼同時生成一個靜態文件的方法

  VBNET

  <%@ Page Language=VB %>

  <!DOCTYPE html PUBLIC //WC//DTD XHTML Transitional//EN

  transitionaldtd

  <script runat=server

  Function CreateDataSource() As ICollection

  Dim dt As SystemDataDataTable = New SystemDataDataTable

  Dim dr As SystemDataDataRow

  dtColumnsAdd(New SystemDataDataColumn(學生班級 GetType(SystemString)))

  dtColumnsAdd(New SystemDataDataColumn(學生姓名 GetType(SystemString)))

  dtColumnsAdd(New SystemDataDataColumn(語文 GetType(SystemDecimal)))

  dtColumnsAdd(New SystemDataDataColumn(數學 GetType(SystemDecimal)))

  dtColumnsAdd(New SystemDataDataColumn(英語 GetType(SystemDecimal)))

  dtColumnsAdd(New SystemDataDataColumn(計算機 GetType(SystemDecimal)))

  Dim i As Integer =

  For i = To

  Dim rd As SystemRandom = New SystemRandom(EnvironmentTickCount * i)

  dr = dtNewRow

  dr() = 班級 + iToString

  dr() = 【孟子E章】 + iToString

  dr() = SystemMathRound(rdNextDouble * )

  dr() = SystemMathRound(rdNextDouble * )

  dr() = SystemMathRound(rdNextDouble * )

  dr() = SystemMathRound(rdNextDouble * )

  dtRowsAdd(dr)

  Next

  Dim dv As SystemDataDataView = New SystemDataDataView(dt)

  Return dv

  End Function

  Protected Sub Page_Load(ByVal sender As Object ByVal e As EventArgs)

  If Not IsPostBack Then

  GridViewDataSource = CreateDataSource()

  GridViewDataBind()

  End If

  End Sub

  Protected Overloads Overrides Sub Render(ByVal writer As HtmlTextWriter)

  Dim html As SystemIOStringWriter = New SystemIOStringWriter

  Dim tw As SystemWebUIHtmlTextWriter = New SystemWebUIHtmlTextWriter(html)

  MyBaseRender(tw)

  Dim sw As SystemIOStreamWriter

  sw = New SystemIOStreamWriter(ServerMapPath() False SystemTextEncodingDefault)

  swWrite(htmlToString)

  swClose()

  twClose()

  ResponseWrite(htmlToString)

  End sub

  </script>

  <html xmlns=

  <head>

  

  <title>得到ASPNET生成的HTML</title>

  </head>

  <body>

  <form id=Form runat=server

  <asp:GridView ID=GridView runat=server FontSize=px BackColor=#FFFFFF

  GridLines=Both CellPadding= Width=

  <HeaderStyle BackColor=#EDEDED Height=px />

  </asp:GridView>

  </form>

  </body>

  </html>


From:http://tw.wingwit.com/Article/program/net/201311/13629.html
  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.