aspx page inherits from a 'Page' class (vb.net) : Page Class « Page Lifecycle « ASP.NET Tutorial






<%@ Page Inherits="ParentPage" src="Default.aspx.vb" %>

<html><body>
   <form runat="server">
      <asp:Label id="lblMessage" runat="server" />
   
      <asp:DataGrid id="DataGrid1" 
                    runat="server" 
                    AutoGenerateColumns="True" />
      </asp:DataGrid>
   </form>
</body></html>


File: Default.aspx.vb


Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.OleDb

Public Class ParentPage : Inherits Page
   public lblMessage as Label
   public DataGrid1 as DataGrid
   
   private strConnString as string = "Provider=" & _
      "Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=yourDatabase.mdb"
   private objConn as new OleDbConnection(strConnString)
   
   sub Page_Load(Sender as Object, e as EventArgs) 
      if Not Page.IsPostBack then
         FillDataGrid()
      end if
   end sub

   private sub FillDataGrid(Optional EditIndex as integer=-1)
      dim objCmd as OleDbCommand = new OleDbCommand("select * from tblUsers", objConn)
      dim objReader as OleDbDataReader
       
      try
         objCmd.Connection.Open()
         objReader = objCmd.ExecuteReader
      catch ex as OleDbException
         lblMessage.Text = "Error retrieving from the database."
      end try
       
      DataGrid1.DataSource = objReader
      DataGrid1.DataBind()
       
      objReader.Close
      objCmd.Connection.Close()
   end sub
    
End Class








5.1.Page Class
5.1.1.Fundamental properties in The Page Class
5.1.2.aspx page inherits from a 'Page' class (C#)
5.1.3.aspx page inherits from a 'Page' class (vb.net)
5.1.4.Expose the control through a page property
5.1.5.Page.ErrorPage
5.1.6.Page.HasControls
5.1.7.Is page valid
5.1.8.Page.ResolveUrl