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@\/  <(.'.)>

Comments

  1. Try this condition:

    if (string.IsNullOrWhiteSpace(textBox1.Text))

    ReplyDelete

Post a Comment

Popular posts from this blog

How to make and use web service in Microsoft Dynamics Navision.

How to use Format function in Microsoft Dynamics Navision.

How to create simple report in Microsoft Dynamics Navision.