Asp.net 在初始化之后、页面加载之前运行

Asp.net 在初始化之后、页面加载之前运行,asp.net,vb.net,Asp.net,Vb.net,由于ddlPlant\u SelectedIndexChanged导致回发后,我需要设置setHttpContext.Current.Session(“PlantNumber”)。这需要在Site.Master中加载ddlPlant之后,但在Default.aspx中的代码需要该值之前发生 Public Class SiteMaster Inherits MasterPage Protected Sub Page_Init(ByVal sender As Object, ByVal e

由于
ddlPlant\u SelectedIndexChanged
导致回发后,我需要设置set
HttpContext.Current.Session(“PlantNumber”)
。这需要在Site.Master中加载ddlPlant之后,但在Default.aspx中的代码需要该值之前发生

Public Class SiteMaster Inherits MasterPage
    Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Init
        If (Not Page.IsPostBack) Then
            ddlPlant.DataSource = myDataSource
            ddlPlant.DataBind()
            ddlPlant.SelectedValue = "1"
        End If

        HttpContext.Current.Session("PlantNumber") = ddlPlant.SelectedValue  
    End Sub

    Protected Sub ddlPlant_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlPlant.SelectedIndexChanged
    End Sub
End Class


Public Class _Default Inherits Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Dim units As New List(Of EquipmentModel)
        For Each unit As EquipmentModel In getUnits.Out.Results
            If (CStr(unit.Plant_ID) = HttpContext.Current.Session("PlantNumber")) Then
                units.Add(unit)
            End If
        Next

        gvEquipmentUnit.DataSource = units.OrderBy(Function(n) n.Equipment_ID)
        gvEquipmentUnit.DataBind()
End Sub
对于上面的代码,当回发后设置
会话(“PlantNumber”)
时,ddlPlant.SelectedIndex=Nothing,ddlPlant.SelectedValue为空字符串


我已尝试将
会话(“PlantNumber”)=ddlPlant.SelectedValue
行移动到Site.Master's Page\u加载,但在默认情况下需要加载后运行。aspx.vb

我查看了PreLoad,但显然它对Master Page不起作用

最终,我决定不使用会话变量,而是直接从任何需要加载该值的页面(几乎所有页面)调用控件:


对不起,这个坏建议。
DirectCast(Master.FindControl("ddlPlant"), DropDownList).SelectedValue