mypage.vb

来自「asp.net技术内幕的书配源码」· VB 代码 · 共 55 行

VB
55
字号
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Public Class myPage
  Inherits Page

  Dim txtTextBox As New TextBox
  Dim lblLabel As New Label

  Protected Overrides Sub CreateChildControls

  ' Add Opening HTML Tags
  Dim strOpenHTML As String
  strOpenHTML = "<html><head><title>My Page</title></head>"
  strOpenHTML &= "<body>Enter some text:"
  Controls.Add( New LiteralControl( strOpenHTML ) )

  ' Add HTMLForm Tag
  Dim frmForm As New HTMLForm
  frmForm.ID = "myForm"
  Controls.Add( frmForm )


  ' Add a TextBox
  txtTextBox.ID = "myTextBox"
  frmForm.Controls.Add( txtTextBox )

  ' Add a Button
  Dim btnButton As New Button
  btnButton.Text = "Click Here!"
  AddHandler btnButton.Click, AddressOf Button_Click
  frmForm.Controls.Add( btnButton )

  ' Add Page Break
  frmForm.Controls.Add( New LiteralControl( "<p>" ) )

  ' Add a Label
  lblLabel.ID = "myLabel"
  frmForm.Controls.Add( lblLabel )

  ' Add Closing HTML Tags
  Dim strCloseHTML As String
  strCloseHTML = "</form></body></html>"
  Controls.Add( New LiteralControl( strCloseHTML ) )

  End Sub

  Sub Button_Click( s As Object, e As EventArgs )
    lblLabel.Text = txtTextBox.Text
  End Sub

End Class

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?