I still think you need to scrap everything you have and start over.
I don't believe you really understand what a class is, and that first one I posted was not a very good representation of a real class.

See below for a simple class for writing to a web page - I say "writing to a web page" because one of the documents methods calls the System.Web.HTTPContext.Current.Response.Write method, which is specific to ASP.Net.

Friend Class myHelloWorldClass

    'Private member variable accessible only
    'to the class
    Private m_sGreeting As String

    'Accessor method, controlled aliased
    'READ/WRITE access to your class variable
    Public Property Message() As String
        Get
            Return m_sGreeting
        End Get
        Set(ByVal sMsg As String)
            m_sGreeting = sMsg
        End Set
    End Property

    'The constructor, initialization for
    'your object
    Protected Friend Sub New()
        m_sGreeting = "Hello world!"
    End Sub

    'over loaded constructor
    Protected Friend Sub New(ByVal sMsg As String)
        Me.New()
        m_sGreeting = sMsg
    End Sub

    'Public class method, something this
    'class can do for you.
    Protected Friend Sub Greet()
        HttpContext.Current.Response.Write(m_sGreeting)
    End Sub

    'Clean up
    Protected Overrides Sub Finalize()

    End Sub

End Class

i just need a help on modification on the above source code that i have send.
the code is working fine but just need a modification as what i have explained above.
just need help a modification on the below code...
can you please help me on that...

i need to a design page which have few checkboxes, few text boxes and few yes/no radio buttons. i need to write a validation function in class file to validate this controls are checked and filled. (some of the controls is optional can be filled/checked or leave it blank).
once the class function done i need to call/use the class in the form page in a button click.
so far i have done checking on checkboxes but i have problem to validate other control button such as radio button & text boxes

Button click

 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

        Dim chkbox As CheckBox() = {checkbox1, checkbox2, checkbox3, checkbox4, _
                                    checkbox5, checkbox6, checkbox7, checkbox8, checkbox9}

        'Dim chkbox As CheckBox() = {RadioButton1, RadioButton2, RadioButton3, RadioButton4}
        Dim txtmsg = objclsKYC.InfoCheking(chkbox)

        If txtmsg = "" Then
            'to update the info to database
            MsgBox(txtmsg)
        Else
            'to prompt err msg
            MsgBox(txtmsg)
            Button1.Enabled = False
        End If

    End Sub

class function

 Public Function InfoCheking(ByVal CheckBoxArray() As Control) As String

        For Each Me.chk In CheckBoxArray
            If Not (Me.chk.Checked) Then
                Me.strReturn = "Please check all the boxes"
                Me.chk.ForeColor = Color.Red
            Else
                Me.strReturn = "Information has been updated"
                'update to database
                Me.chk.ForeColor = Color.Black
            End If
        Next

        Return Me.strReturn
 End Function

Your MsgBox function works - the ForeColor does not, correct?

That is because you are changing the property of a copy of the CheckBox object, and not rendering it.
That code I wrote was for a Windows Form - you can't change the ForeColor of the control like that in ASP.

Actually, even that ForeColor code works - ForeColor only affects the CheckBox.text property. You're probably looking for the label text to change instead

ok..can you help me to modify the code to validate the control boxes...

I am posting code for a partial class.
This partial class only checks TextBox, CheckBox, and RadioButton to evaluate whether the TextBoxes have text, CheckBoxes are checked, and RadioButtons are checked - it does not attempt to evaluate whether the RadioButtons are part of a set.

Since RadioButtons 1 & 2 are a set, one of those will be marked as invalid - even though it cannot be Checked=True if the other RadioButton in the set is already True. The same issue holds true with RadioButtons 3 & 4.
You will have to write your own code to evaluate these cases

  1. The class will return a Boolean value that you can check.
  2. Usage of the class is in the remarks section of the class.
  3. You have to code your own user notification.

Good Luck.

Partial Public Class ControlValueValidator
    '
    ' Partial Public Class ControlValueValidator
    ' Author: J.Knapp 2012-11-31 01:45 UTC
    ' Purpose: minimal validation to ensure ASP form controls have values
    ' - Currently supports only TextBox, CheckBox, and RadioButton
    ' - Does not evaluate RadioButton exclusivity|grouping
    '
    ' Usage Case 1:
    ' New myValidator(myControl)
    ' myValidator.IsValid = True | False | Nothing
    '
    ' Usage Case 2:
    ' New myValidator()
    ' myValidator.ValidateControl(myControl)
    ' myValidator.IsValie = True | False | Nothing
    '

    Private m_ValidationString As String
    Private m_IsValid As Boolean

    Public Sub New()
        m_ValidationString = "Control has not been validated."
        m_IsValid = Nothing
        Return
    End Sub

    Public Sub New(myControl As Control)
        ValidateControl(myControl)
        m_ValidationString = "Control has not been validated."
        m_IsValid = Nothing
        Return
    End Sub

    Public Sub ValidateControl(myControl As Control)
        ' this is ugly, unable to determine better syntax at this time
        If TypeOf myControl Is CheckBox Then
            Dim m_ctrl As CheckBox = CType(myControl, CheckBox)
            If m_ctrl.Checked Then
                ' checked
                m_ValidationString = myControl.ID & " is checked."
                m_IsValid = True
                Debug.Print(m_ValidationString)
            Else
                ' not checked
                m_ValidationString = myControl.ID & " is not checked."
                m_IsValid = False
                Debug.Print(m_ValidationString)
            End If
        ElseIf TypeOf myControl Is RadioButton Then
            Dim m_ctrl As RadioButton = CType(myControl, RadioButton)
            If m_ctrl.Checked Then
                ' checked
                m_ValidationString = myControl.ID & " is checked."
                m_IsValid = True
                Debug.Print(m_ValidationString)
            Else
                ' not checked
                m_ValidationString = myControl.ID & " requires a selection."
                m_IsValid = False
                Debug.Print(m_ValidationString)
            End If
        ElseIf TypeOf myControl Is TextBox Then
            Dim m_ctrl As TextBox = CType(myControl, TextBox)
            If Not (Trim(m_ctrl.Text) = "") Then
                ' has text
                m_ValidationString = myControl.ID & " has text present."
                m_IsValid = True
                Debug.Print(m_ValidationString)
            Else
                ' no text
                m_ValidationString = myControl.ID & " requires text entry."
                m_IsValid = False
                Debug.Print(m_ValidationString)
            End If
        Else

            m_ValidationString = myControl.GetType.ToString _
                                & " is not supported by ControlValueValidator"
            m_IsValid = Nothing
        End If
    End Sub

    Public ReadOnly Property IsValid() As Boolean
        Get
            Return m_IsValid
        End Get
    End Property


    Public Property ValidationString() As String
        Get
            Return m_ValidationString
        End Get
        Set(ByVal value As String)
            m_ValidationString = value
        End Set
    End Property

    ' use the default destructor
    'Protected Overrides Sub Finalize()
    '    Return
    'End Sub

End Class

With that class, and this procedure in your Button_Click event:

Protected Sub Button1_Click(ByVal sender As Object, _
                            ByVal e As EventArgs) Handles Button1.Click

    Dim ControlsToValidate() As Control = {checkbox1, checkbox2, checkbox3, _
                                checkbox4, checkbox5, checkbox6, checkbox7, _
                                checkbox8, checkbox9, RadioButton1, _
                                RadioButton2, RadioButton3, RadioButton4}

    Dim myValidator As New ControlValueValidator()
    For Each myControl As Control In ControlsToValidate
        myValidator.ValidateControl(myControl)
        If Not myValidator.IsValid Then
            ' control is invalid, notify user
        End If
    Next

    ' if we're all done with the Collection, let's free up the resources
    Erase ControlsToValidate

End Sub

I get the following debug output:

checkbox1 is not checked.
checkbox2 is not checked.
checkbox3 is not checked.
checkbox4 is not checked.
checkbox5 is not checked.
checkbox6 is not checked.
checkbox7 is not checked.
checkbox8 is not checked.
checkbox9 is not checked.
RadioButton1 is not checked.
RadioButton2 is not checked.
RadioButton3 is not checked.
RadioButton4 is not checked.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.