不會激發我有以下BasePage類...ASP.NET BasePage類的Page_Load上回發
Public Class BasePage
Inherits System.Web.UI.Page
Private litError As Literal
Protected SO As Session
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SO = Session.Item("SO")
If SO Is Nothing Then
Session.Abandon()
Response.Redirect("~/timeout.htm")
End If
litError = Page.FindControl("litError")
If litError IsNot Nothing Then
litError.Visible = False
End If
End Sub
Protected Sub ShowMessage(ByVal Message As String)
Show(Message, "message")
End Sub
Protected Sub ShowError(ByVal Message As String)
Show(Message, "error message")
End Sub
Protected Sub ShowSuccess(ByVal Message As String)
Show(Message, "success message")
End Sub
Private Sub Show(ByVal Message As String, ByVal CssClass As String)
If litError IsNot Nothing Then
litError.Text = String.Format("<span class=""{0}"">{1}</span>", CssClass, HttpUtility.HtmlEncode(Message))
litError.Visible = True
End If
End Sub
End Class
在這個程序裏的每個頁面繼承這個類。 SO變量表示一個自定義的會話類,這非常簡單,並且只是在整個應用程序中持有一些基本設置。問題是,如果發生自然回發,則此基類中的Page_Load不會觸發(在這種情況下,它是通過排序/分頁進行的GridView回發)。然後在我的代碼中,當我引用SO時,我得到一個空引用異常,因爲它沒有被從會話中拉出。
爲什麼基頁Page_Load沒有啓動?