Define a class inside page : Class Define « Language Basics « ASP.Net

Home
ASP.Net
1.ADO.net Database
2.Ajax
3.Asp Control
4.Collections
5.Components
6.Data Binding
7.Development
8.File Directory
9.HTML Control
10.Language Basics
11.Login Security
12.Mobile Control
13.Network
14.Page
15.Request
16.Response
17.Server
18.Session Cookie
19.Sitemap
20.Theme Style
21.User Control and Master Page
22.Validation by Control
23.Validation by Function
24.WebPart
25.WPF
26.XML
ASP.Net » Language Basics » Class Define 
Define a class inside page

<%@ page language="vb" runat="server" %>

<script runat="server">

Public Class Book
  Private _Title As String
  Private _Isbn As Integer
  Private _Price As Decimal

  Public Sub New()
    _Title = "title"
    _Isbn = 999999999
  End Sub

  Public ReadOnly Property TitleInfo As String
    Get
      Return _Title & " <i>(ISBN: " & _Isbn & ")</i>"
    End Get
  End Property

  Public ReadOnly Property Title As String
    Get
      Return _Title
    End Get
  End Property

  Public ReadOnly Property Isbn As Integer
    Get
      Return _Isbn
    End Get
  End Property

  Public Property Price As Decimal
    Get
      Return _Price
    End Get
    Set(value As Decimal)
      _Price = value
    End Set
  End Property
End Class

Sub Page_Load()
  Dim MyBook As New Book()
  Response.Write("<b>New book 'MyBook' created.</b>")

  MyBook.Price = "39.99"
  Response.Write("<br/>Title info: " & MyBook.TitleInfo)
  Response.Write("<br/>Price: $" & MyBook.Price & "<br/>")
End Sub

</script>

           
       
Related examples in the same category
1.Define two classes inside a page
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.