I am currently learning to use ASP.NET 2.0 with Visual Web Developer.
For my previous project, I used ASP 3.0 with OOP approach where all my files are .asp regardless they are ASP page or class file.
In .NET, we can use code behind and Master/Detail design.
I tried to practice OOP approach in ASP.NET but yet find any sample or tutorial for it.
I tried to use a class file (eg. Bank.vb) where it will stored inside App_Code folder.
Bank.vb:
In MasterPage.master.vb, I have:Code:Public Class Bank Private strProperty1 As String Private strProperty2 As String Public Property Property1() As String Get Return strProperty1 End Get Set(ByVal value As String) strProperty1 = value End Set End Property Public Property Property2() As String Get Return strProperty2 End Get Set(ByVal value As String) strProperty2 = value End Set End Property End Class
ProductReport.aspx.vb:Code:Partial Class MasterPage Inherits System.Web.UI.MasterPage Private objBank As New Bank Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Page.IsPostBack Then objBank.Property1 = DropDown1.SelectedValue objBank.Property2 = DropDown2.SelectedValue End If End Sub Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click If RadioButton1.SelectedIndex = 1 Then Response.Redirect("BankReport.aspx") Else Response.Redirect("ProductReport.aspx") End If End Sub Protected Overrides Sub Finalize() objBank = Nothing '<-Required? MyBase.Finalize() End Sub End Class
My problem is why oBank.Property1 = Nothing ?Code:Imports Bank Partial Class ProductReport Inherits System.Web.UI.Page Public oBank As New Bank Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Response.Write(oBank.Property1) '<- oBank.Property1 = Nothing End Sub Protected Overrides Sub Finalize() oBank = Nothing '<-Required? MyBase.Finalize() End Sub End Class
It should has a value from DropDown1.SelectedValue when I click btnSubmit.
For example, DropDown1.SelectedValue = "Public Bank LLC"
Then this value will assign to Property1 through objBank.Property1
and share in ProductReport.aspx using oBank.Property1
Can you tell me what's wrong with my code?
Should I initialize all my variables in Bank.vb class using:
Finally, do I need to dereference the objBank and oBank using Finalize Sub?Code:Public Sub New() strProperty1 = "" strProperty2 = "" End Sub




Reply With Quote