form objects into class objects

G

Guest

Hi I have created a class that inherits from dictionarybase code below.

Public Class FrmLabels
Inherits Label
Private m_Lbl As Label

Public Property lbl() As Label
Get
Return m_Lbl
End Get
Set(ByVal Value As Label)
m_Lbl = Value
End Set
End Property

Sub New(ByVal lbl As Label)
Me.m_Lbl = m_Lbl
End Sub

End Class

Public Class FrmDDL
Inherits DropDownList
Private m_DDL As DropDownList

Public Property DDL() As DropDownList
Get
Return m_DDL
End Get
Set(ByVal Value As DropDownList)
m_DDL = Value
End Set
End Property

Sub New(ByVal DDL As DropDownList)
Me.m_DDL = m_DDL
End Sub

End Class

Public Class FrmTxt
Inherits HtmlInputText
Private m_DDL As HtmlInputText

Public Property DDL() As HtmlInputText
Get
Return m_DDL
End Get
Set(ByVal Value As HtmlInputText)
m_DDL = Value
End Set
End Property

Sub New(ByVal DDL As HtmlInputText)
Me.m_DDL = m_DDL
End Sub

End Class

Public Class FormDictionary
Inherits DictionaryBase

Sub add(ByVal key As String, ByVal D As Object)
Me.Dictionary.Add(key, D)
End Sub

Sub remove(ByVal key As String)
Me.Dictionary.Remove(key)
End Sub

Default Property item(ByVal key As String) As Object
Get
Return Me.Dictionary.Item(key)
End Get
Set(ByVal Value As Object)
Me.Dictionary.Item(key) = Value
End Set
End Property

Function contains(ByVal key As String) As Boolean
Return Me.Dictionary.Contains(key)
End Function
End Class

Basically the 3 types of objects i want to pass from my page into a function
defined in another class are label, htmlinputtext and dropdownlist.

and i have this code in my form

For Each ctrl In pnlForm.Controls
If TypeOf ctrl Is HtmlInputText Then
frmDict.add(ctrl.ID, New FrmTxt(CType(ctrl,
HtmlInputText)))
End If
If TypeOf ctrl Is Label And ctrl.ID <> "" Then
frmDict.add(ctrl.ID, New FrmLabels(CType(ctrl,
Label)))
End If
If TypeOf ctrl Is DropDownList Then
frmDict.add(ctrl.ID, New FrmDDL(CType(ctrl,
DropDownList)))
End If
If TypeOf ctrl Is suppliersList Then
frmDict.add(ctrl.ID, ctrl)
End If
Next

This adds each of the objects into the dictionary however i cant get the ID.
I am using the syntax ctype(frmdict.item("lblReqBy"), label).ID but it
returns nothing.

I have a web user control on their (SuppliersList) which contains a
dropdownlist, i haven't created a class for this as its only on the page
once, if i use the following syntax

ctype(frmdict.item("Suppliers1"), suppliersList).Controls.Item(0).ID

It gives me the ID of the dropdownlist. Can anyone help me out as to why I
can't access the ID property of the controls. Basically I will populate the
text property, selectedvalue property in a function i am writing and modify
the page appropriately, the reason i am doing this is because the same
routine is used on two of my pages and i only want to write it once and stick
it in a class.

TIA
 
G

Guest

Hi i have played around with it this morning and noticed that each of the sub
new in the class was wrong so i changed it to read me.m_lbl = lbl. However i
still had the same issues described

Sub New(ByVal lbl As Label)
Me.m_Lbl = m_Lbl
End Sub

i also changed my for next loop to read

For Each ctrl In pnlForm.Controls
If TypeOf ctrl Is HtmlInputText Then
frmDict.add(ctrl.ID, ctrl)
End If
If TypeOf ctrl Is Label And ctrl.ID <> "" Then
frmDict.add(ctrl.ID, ctrl)
End If
If TypeOf ctrl Is DropDownList Then
frmDict.add(ctrl.ID, ctrl)
End If
If TypeOf ctrl Is suppliersList Then
frmDict.add(ctrl.ID, ctrl)
End If
Next

This appears to be working ok, run a few tests in the immediate window. In
my vb.net book it says to create classes like i have done and add them to a
dictionary or collection object. I think the idea is to create early bound
objects i remember something about how it would operate faster, although
there must be something wrong in what i have written so far.

TIA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top