我知道这是一个非常基本的问题,但我找不到答案。有很多网页说 page.init 不会在回帖时触发,例如:http: //www.dotnetfunda.com/interview/exclusive/x3224-what-is-the-difference-between-the-pageinit -and-pageload-events.aspx。请看下面的代码:
Public Class _Default
Inherits System.Web.UI.Page
Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
MsgBox("Test Init") 'Line 5
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack = True Then
MsgBox("PostBack") 'line 9
End If
MsgBox("Test Load")
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = "Hello"
End Sub
End Class
每次单击按钮时,第 5 行和第 9 行的消息框都会触发。这意味着 Init 事件在回发时触发。我显然忘记了一些非常基本的东西。