check whether a textbox is empty

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yuelin

    #1

    check whether a textbox is empty

    Hi there

    What's the best way of checking whether a textbox is empty? Thanks.

    Yuelin


  • Chris Capel

    #2
    Re: check whether a textbox is empty

    If you want to ignore spaces, then

    textBox1.Text.T rim() == ""

    otherwise use

    textBox1.Text == ""

    Chris
    "Yuelin" <liang@lineone. net> wrote in message
    news:#OCYJxPXDH A.608@TK2MSFTNG P12.phx.gbl...[color=blue]
    > Hi there
    >
    > What's the best way of checking whether a textbox is empty? Thanks.
    >
    > Yuelin
    >
    >[/color]


    Comment

    • Mark Marsella

      #3
      Re: check whether a textbox is empty

      In article <#OCYJxPXDHA.60 8@TK2MSFTNGP12. phx.gbl>, liang@lineone.n et says...[color=blue]
      > Hi there
      >
      > What's the best way of checking whether a textbox is empty? Thanks.
      >
      > Yuelin
      >
      >
      >[/color]

      Subclass TextBox and add a IsEmpty Method

      class MyTextBox : TextBox
      {

      public bool IsEmpty()
      {
      return (TextBox.Text == "")
      }

      }
      --
      Thanks
      Mark Marsella

      Comment

      • Chris Capel

        #4
        Re: check whether a textbox is empty

        Seems a bit excessive...


        "Mark Marsella" <news@tersus-solutions.com> wrote in message
        news:MPG.199c92 9ebd38c93798968 a@news.cis.dfn. de...[color=blue]
        > Subclass TextBox and add a IsEmpty Method[/color]


        Comment

        • Nick Berardi

          #5
          Re: check whether a textbox is empty

          The more .Net oriented way is to use

          TextBox.Text == String.Empty

          It doesn't really matter but it goes back to that magic number thing.
          There should never be an instance theoretically that you should ever
          have to put a string or number in your program.

          Nick

          Mark Marsella wrote:
          [color=blue]
          > In article <#OCYJxPXDHA.60 8@TK2MSFTNGP12. phx.gbl>, liang@lineone.n et says...
          >[color=green]
          >>Hi there
          >>
          >>What's the best way of checking whether a textbox is empty? Thanks.
          >>
          >>Yuelin
          >>
          >>
          >>[/color]
          >
          >
          > Subclass TextBox and add a IsEmpty Method
          >
          > class MyTextBox : TextBox
          > {
          >
          > public bool IsEmpty()
          > {
          > return (TextBox.Text == "")
          > }
          >
          > }[/color]

          Comment

          • Gregory Persson

            #6
            Re: check whether a textbox is empty

            I always do

            textBox1.Text.L ength == 0

            I read somewhere that checking the string's length is a faster operation.
            Although the performance gain would probably only be useful in a loop, and
            there's little chance you're doing this in a loop...

            ~Greg

            "Chris Capel" <chris@nowhere. com> wrote in message
            news:#cdAa1PXDH A.1384@TK2MSFTN GP10.phx.gbl...[color=blue]
            > If you want to ignore spaces, then
            >
            > textBox1.Text.T rim() == ""
            >
            > otherwise use
            >
            > textBox1.Text == ""
            >
            > Chris
            > "Yuelin" <liang@lineone. net> wrote in message
            > news:#OCYJxPXDH A.608@TK2MSFTNG P12.phx.gbl...[color=green]
            > > Hi there
            > >
            > > What's the best way of checking whether a textbox is empty? Thanks.
            > >
            > > Yuelin
            > >
            > >[/color]
            >
            >[/color]


            Comment

            Working...