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

Home
ASP.NET Tutorial
1.ASP.Net Instroduction
2.Language Basics
3.ASP.net Controls
4.HTML Controls
5.Page Lifecycle
6.Response
7.Collections
8.Validation
9.Development
10.File Directory
11.Sessions
12.Cookie
13.Cache
14.Custom Controls
15.Profile
16.Configuration
17.LINQ
18.ADO.net Database
19.Data Binding
20.Ajax
21.Authentication Authorization
22.I18N
23.Mobile
24.WebPart
25.XML
ASP.NET Tutorial » Page Lifecycle » Page Class 
5.1.3.aspx page inherits from a 'Page' class (vb.net)
<%@ 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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.