VB.NET • Link the Content Page to the Master Page

Listing 4. This is a sample Page_Load event for the EventTester.aspx file. An entry to the textbox control within the master page is logged during the Page_Load and Press Me button events so that you can demonstrate the order of event firing in master/content pages. The textbox exists in the master page, so you need to use the FindControl method to get a reference to it.

Partial Class EventTester_aspx
   Sub Page_Load (ByVal sender As Object, _
      ByVal e As System.EventArgs) Handles Me.Load
      ' Demonstrate the ability to add metadata via 
      ' the master object
      Master.Page.Header.Metadata.Add( _
         "Description", _
         "Sample master/content page")
      ' Get a reference to the textbox in the master 
      ' page
      Dim txtEventLog As TextBox = _
         CType(Master.FindControl("txtEventLog"), _
         TextBox)
      ' Since this is the first event, clear the log
      txtEventLog.Text = ""
      ' Print out the firing of this Page_Load event
      txtEventLog.Text += vbCrLf
      txtEventLog.Text += _
         "Content Page_Load Event Fired"
   End Sub

   Sub btnPressMe_Click(ByVal sender As Object, _
      ByVal e As System.EventArgs)
      ' Get a reference to the textbox in the master 
      ' page
      Dim txtEventLog As TextBox = _
         CType(Master.FindControl("txtEventLog"), _
         TextBox)
      ' Print out the firing of this button click 
      ' event
      txtEventLog.Text += vbCrLf
      txtEventLog.Text += _
         "Press Me Button Event Fired"
   End Sub
End Class