Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have added these codes give below with one ErrorProvider control. Now i don't know how should i alert the user before moving to the next form. I want the button should be disabled until and unless the user doesn't fill all the required field, once it fill all the field, button should be enable so it move to the form2 and so on.

VB
Private Function ValidateFirstName(ByVal name As String) As String
        Dim errorMessage As String = String.Empty
        If name.Length <= 0 Then
            errorMessage = "First name is required."
        End If
        Return errorMessage
    End Function

    Private Sub SBPStep1Btn_Click(sender As Object, e As EventArgs) Handles SBPStep1Btn.Click
        Dim err As String = ValidateFirstName(FNTBox.Text)
        If (err = String.Empty) Then
            ErrorProvider1.SetError(FNTBox, "")
        Else
            ErrorProvider1.SetError(FNTBox, err)
        End If

    End Sub
Posted
Updated 4-Sep-15 18:03pm
v2

1 solution

Hi,

There a lot of methods you can try. Simplest is to:

1. Disable the Submit button on Startup

VB
Private Sub form_Load(...)
btn_submit.enabled = False
End Sub


2. Create a Sub to check all mandatory fields are filled in:
VB
Private Sub CheckAllFilled()
'Define boolean presuming that all fields are filled in.
Dim AllOkay as boolean = True
'Write code for all your fields in a Sub and call it in the Leave event of each control
if textbox1.text = "" then AllOkay = False
if textbox2.text = "" then AllOkay = False
if Checkbox1.checked = False andalso Checkbox2.checked = False then AllOkay = False
If Optionbutton1.Checked = False andalso Optionbutton2.Checked = False then AllOkay = False
If Combobox1.selectedIndex = -1 then AllOkay = False

'Then Enable/Disable btn_Submit
btn_Submit.enabled = AllOkay
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900