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

Thanks for comment

 
Toggle Footer