If else inside a loop in VB.Net

The code below shows the event when a button click is fire

Protected Sub btnFinish_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFinish.Click
         For i As Integer = 0 To Gridview1.Rows.Count - 1 Step i + 1
                Dim TextBox1 As TextBox = DirectCast(Me.Gridview1.Rows(i).FindControl("txtAnswer"), TextBox)
                If TextBox1.Text = String.Empty Then
                    'do something
                ElseIf TexBox1 <> String.Empty Then
                    'do something else
                End If
         Next
End Sub

The problem here is that the only condition being executed is in the If-statement even if it should execute the ElseIf-statement. Can someone explain why and how can I solve this problem? [EDITED]

Answers


a couple of things to note when comparing text/string:

  1. String could be NULL, instead of Empty
  2. use String.IsNULLOrEmpty to check NULL/Empty
  3. String could be WhiteSpace too, use String.IsWhiteSpace to check it
  4. User could enter a few spaces in some cases, if you want to make sure it's correct, use String.Trim to eliminate any unwanted spaces.

normally what I do is: (NOT String.IsNULLOrEmpty(givenText)) AndAlso givenText.Trim.Length <> 0


Need Your Help

buildout deployment strategies

python deployment buildout

So I am applying zc.buildout to an existing django project. I am wondering about deploying it now. How do I achieve the sandbox effect on a production server?

Handling mail forwarding with php

php email exim

I have a feature in my app that handles and parses incoming emails.