Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
For Example I have 3 TextBoxs if one of them have empty value then
i need it alert a message like that >>Please Enter Values into txtName <<<</xml>
Posted
Comments
[no name] 20-Jul-14 10:53am    
And the question or problem is....?
phanithly 20-Jul-14 10:57am    
it my Problem ..
here my code

Public Sub CheckEmptyTextbox(ByVal root As Control)
Dim txt As Control
For Each txt In root.Controls
If TypeOf txt Is TextBox Or TypeOf txt Is ComboBox Then
If txt.Text = "" Then
MsgBox("Please enter .....")
Exit Sub
Exit For
End If
End If
Next
[no name] 20-Jul-14 11:02am    
And you think that we can magically know what it is that "not work good" means? What do you expect MsgBox to do on a web page? Do you think that a user half way around the world will be seeing a window displayed on your web server? Go get the ajaxToolkit and use that.
phanithly 20-Jul-14 10:58am    
but it work not good like i want
phanithly 20-Jul-14 11:05am    
Window Form

Google for "VB.NET Windows Forms Validation" and you'll come up with all kinds of ways to do this.
 
Share this answer
 
Hi,

Use this code to check the blank textbox for a form

VB
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            For Each cntrl As Control In Me.Controls()
                If TypeOf cntrl Is TextBox Then
                    If CType(cntrl, TextBox).Text.Equals(String.Empty) Or (CType(cntrl, TextBox).Text = "") Then
                        MessageBox.Show("Please enter value in " & cntrl.Name.ToString())
                    End If
                End If
            Next
        Catch ex As Exception

        End Try

    End Sub
 
Share this answer
 
Comments
phanithly 31-Jul-14 22:37pm    
Thank you ! :)
Go through this code it may help you.............

i wrote this in c# convert this to vb.net.

C#
private void CheckTxt()
{
  try
  {
   List<Control> c = Controls.OfType<TextBox>().Cast<Control>().ToList();
   for (int i = 0; i < c.Count; i++)
   {
     if (c[i].Text.Trim () == string.Empty)
     {

       MessageBox.Show("Please enter.......");
       return;
     }
   }

  }
  catch (Exception ex)
  {

    throw ex;
  }
}
 
Share this answer
 
Comments
phanithly 31-Jul-14 22:37pm    
Thank you so much !
it work as well
simply do this,use loop if you want the same way you did..

VB
If YourTextBox.Text = "" Or String.IsNullOrEmpty(YourTextBox.Text) Then
            MessageBox.Show("Please Enter Values into YourTextBox")
            txtFileName.Focus()
            Exit Sub
End If
 
Share this answer
 
v2
Use The Code As:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            For Each cntrl As Control In Me.Controls()
                If TypeOf cntrl Is TextBox Then
                    If CType(cntrl, TextBox).Text.Equals(String.Empty) Or (CType(cntrl, TextBox).Text = "") Then
                        MessageBox.Show("Please enter value in " & cntrl.Name.ToString())
                        cntrl.Focus()
                        
                    End If
                End If
            Next
        Catch ex As Exception
 
        End Try
 
    End Sub
 
Share this answer
 
i am writing in c# you can change it to VB via converter,


for example : TextBox txtName;


if(txtName.Text.Trim().Length == 0)
{

MessageBox.Show("Please Enter Values into txtName");

}

else
{

MessageBox.Show("txtName is not Empty");

}
 
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