If (textbox.name == null) ? Howto

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gohalien
    New Member
    • Mar 2007
    • 7

    If (textbox.name == null) ? Howto

    I am writing some code, and I wanna "ask" if an object name is not null (aka, the object exist) then do some work, else, do other work...

    Of course, by doing "If (textbox.name == null)" I get the error NullReferenceEx ception.

    Example of what I want to do in a function that have a public textbox object:
    private TextBox det;
    public TextBox Det
    {
    get { return det; }
    set { det = value; }
    }


    if (det.Name != "")
    {
    Funciones.Detal le(det, CodBrowse, this.Text);
    }
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    Please check with isDBNull instead of null.
    e.g.

    If IsDBNull(textbo x.name) = True

    end if

    Comment

    • TRScheel
      Recognized Expert Contributor
      • Apr 2007
      • 638

      #3
      Originally posted by shweta123
      Hi,

      Please check with isDBNull instead of null.
      e.g.

      If IsDBNull(textbo x.name) = True

      end if

      Actually, I believe he's trying to see if the textbox exists... instead of

      if (det.Name != null)

      he should just do

      if (det != null)

      Comment

      • jaeden99
        New Member
        • May 2007
        • 19

        #4
        'This checks to see if there are spaces in a textbox(if textbox is empty).
        'I'm not sure if the textbox field qualifies for null. I think we only use that in database fields(or instances).

        Are you trying to see if the textbox is empty?

        if textboxname.tex t = " " then

        'code to do what you want or not want

        end if

        Comment

        • TRScheel
          Recognized Expert Contributor
          • Apr 2007
          • 638

          #5
          Originally posted by jaeden99
          'This checks to see if there are spaces in a textbox(if textbox is empty).
          'I'm not sure if the textbox field qualifies for null. I think we only use that in database fields(or instances).

          Are you trying to see if the textbox is empty?

          if textboxname.tex t = " " then

          'code to do what you want or not want

          end if
          Use string.Empty instead of ""

          If tomorrow they changed what an empty string was declared as, you would have to change all your code, but if you used string.Empty, it would be updated for you.

          Comment

          • teakwood85
            New Member
            • May 2007
            • 5

            #6
            Try to use String.IsNullOr Empty();

            -Jati

            Comment

            Working...