Breaking News
Loading...
Thursday, 11 October 2012

How to avoid user to leave textbox empty in C#.Net ?

=> Create project.
=> take textbox from toolbox
=> select textbox and goto propeties window and click on event tab.
=> double click on KeyLeave event.
=> write following code

CODE:


 //this code is for when user leave text box without entering any number then it give error.
       private void textbox1_Leave(object sender, EventArgs e)
        {
            if (textbox1.Text=="")
            {
                MessageBox.Show("Pleasr fill up the value in text box","Error");
                textbox1.Focus();
            }
        }


--
/\/ir@\/  <(.'.)>

1 comments:

  1. Try this condition:

    if (string.IsNullOrWhiteSpace(textBox1.Text))

    ReplyDelete
:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

Thanks for comment

 
Toggle Footer