Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll
<Asp.net blog>
<personal site>
[prev. Lesson]  Literal Controls Rock! Blows Away response.write
     [next Lesson]  Controls Added Dynamically

Visual Inheritance/CBF by Charles Carroll

This page demonstrates how a graphic designer and a coder could work together yet ALL code is one file and all graphic design is in another. This means that the graphic designer is not distracted by code and will not damage it.

Visual Inheritance / Code Behind Forms is one of the biggest innovation in ASP+ that will revolutinize web development.

The page has only controls. No PageLoad events, etc. It inherits all that from a VB7 Class file. Here is the page:

   filename=/experiments/inheritancevisual/formpresentationv3.aspx

<Test Script Below>


<%@Page Language="VB" Inherits="TheComponent" Src="formpresentationv3cbf.vb" Trace="False" %>
<html><head>
<title>Inherit A Simple Class</title>
</head>
<body bgcolor="#FFFFFF">
<h3><font face="Verdana">VB Visual Inheritance/CBF</font></h3>
<form runat="server">
<asp:Table runat="server" GridLines="both" BorderWidth="1px">
<asp:TableRow>
<asp:TableCell>City</asp:TableCell>
<asp:TableCell><ASP:DropDownList id="Cy" datatextfield="city" DataValueField="city" runat="server"/></asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell>State</asp:TableCell>
<asp:TableCell><ASP:DropDownList id="st" datatextfield="state" DataValueField="state" runat="server"/></asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell>Zip</asp:TableCell>
<asp:TableCell><ASP:DropDownList id="zp" datatextfield="zip" DataValueField="zip" runat="server"/></asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
</body></html>

The VB7 Class file with all the code is here:

filename=/experiments/inheritancevisual/formpresentationv3cbf.vb

option strict off
Imports System
Imports System.Collections
Imports System.Data
Imports System.Data.oledb
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Public Class TheComponent
    Inherits System.Web.UI.Page
    Private _someproperty As String

    protected cy as DropDownList
    protected st as DropDownList
    protected zp as DropDownList

    Public Sub New()
            MyBase.New()
            _someproperty = "property"
    End Sub
    
    Sub Page_Load(Src As Object, E As EventArgs) 
        Dim strConn as string ="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & server.mappath("/experiments/data/biblio.mdb") & ";" 
     
        Dim strSQL as string ="select distinct city from publishers"
        Dim Conn as New OLEDBConnection(strConn) 
        Dim Cmd as New OLEDBCommand(strSQL,Conn) 
        Conn.Open() 
        cy.DataSource = Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection) 
        cy.DataBind() 

        strSQL="select distinct state from publishers"
        Dim conn2 as New OLEDBConnection(strConn) 
        Dim Cmd2 as New OLEDBCommand(strSQL,Conn2) 
        Conn2.Open() 
        st.DataSource = Cmd2.ExecuteReader(system.data.CommandBehavior.CloseConnection) 
        st.DataBind()     
     
        strSQL="select distinct zip from publishers"
        Dim conn3 as New OLEDBConnection(strConn) 
        Dim Cmd3 as New OLEDBCommand(strSQL,Conn3) 
        Conn3.Open() 
        zp.DataSource = Cmd3.ExecuteReader(system.data.CommandBehavior.CloseConnection) 
        zp.DataBind()     
    End Sub 

    
    Public Function SomeFunction As String
           SomeFunction="function"
    End Function

       Public Property SomeProperty() As String
    Get 
            return _Someproperty
    End Get
    Set
            _someproperty = Value
    End Set
    End Property
End Class
Send Us a Holiday Gift!. Charles celebrates Christmas, Jewish holidays, Kwanza, Chinese New Year, Japanese Holidays, Secretary Day, High Muslim Holy Days, Pagan & Wicca holidays, and many more! - send a gift any HOLIDAY. 2004 gift gallery & 2005 gift gallery