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






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

<html><body>
   <form runat="server">
      <asp:Label id="lblMessage" runat="server" />
   
      <asp:DataGrid id="DataGrid1" 
                    runat="server" 
                    BorderColor="black" 
                    GridLines="Vertical" 
                    cellpadding="4" 
                    cellspacing="0" 
                    width="100%" 
                    Font-Name="Arial" 
                    Font-Size="8pt" 
                    HeaderStyle-BackColor="#cccc99"
                    ItemStyle-BackColor="#ffffff"
                    AlternatingItemStyle-Backcolor="#cccccc"
                    AutoGenerateColumns="True" />
      </asp:DataGrid>
   </form>
</body></html>

File: Default.aspx.cs

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;

public class ParentPage : Page {
   public Label lblMessage;
   public DataGrid DataGrid1;
   
   private OleDbConnection objConn;
   
   void Page_Load(Object Sender, EventArgs e) {
      objConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("EmployeeDatabase.mdb"));
      if (!Page.IsPostBack) {
         FillDataGrid();
      }
   }

   private void FillDataGrid() {
      FillDataGrid(-1);   
   }

   private void FillDataGrid(int EditIndex) {
      OleDbCommand objCmd = new OleDbCommand("select * from employee", objConn);
      OleDbDataReader objReader;
       
      try {
         objCmd.Connection.Open();
         objReader = objCmd.ExecuteReader();

         DataGrid1.DataSource = objReader;
         DataGrid1.DataBind();

         objReader.Close();
      } catch (OleDbException ex) {
         lblMessage.Text = "Error retrieving from the database.";
      }
       
      objCmd.Connection.Close();
   }
    
}








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