form objects into class objects

Discussion in 'ASP .Net' started by =?Utf-8?B?c3RldmVuIHNjYWlmZQ==?=, Jul 5, 2006.

  1. 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
     
    =?Utf-8?B?c3RldmVuIHNjYWlmZQ==?=, Jul 5, 2006
    #1
    1. Advertising

  2. 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

    "steven scaife" wrote:

    > 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
     
    =?Utf-8?B?c3RldmVuIHNjYWlmZQ==?=, Jul 6, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. E11
    Replies:
    1
    Views:
    4,953
    Thomas Weidenfeller
    Oct 12, 2005
  2. Replies:
    1
    Views:
    3,935
    Tim B
    Jan 7, 2006
  3. christopher diggins
    Replies:
    16
    Views:
    790
    Pete Becker
    May 4, 2005
  4. Joseph Turian
    Replies:
    5
    Views:
    631
  5. 7stud
    Replies:
    11
    Views:
    755
    Dennis Lee Bieber
    Mar 20, 2007
Loading...

Share This Page