Abhijit  Patil

Abhijit Patil

  • 543
  • 3.9k
  • 1.3m

how to identify the empty textbox in asp.net

Apr 11 2015 7:07 AM
hi folks,


In asp.net  i bind all textbox to textchange event and get the sender value of textbox and do my operation. 

textchange event is work fine .but problem is that when my textbox is empty and i pressed enter then the event is not fire.
how to solve my problem.

my code snippest as below

  protected void txtName_TextChanged(object sender, EventArgs e)
    {
        TextBox tb = sender as TextBox;


        if (tb.ID == "TextBox1")
        {


            if (tb.Text == string.Empty)
            {
                Label1.Text = "Please enter input";
            }
            else if (TextBox1.Text == "001")
            {



                Label1.Text = "user is valid";
                TextBox2.Focus();

            }
            else
            {
                Label1.Text = "user is not valid";
                TextBox2.Focus();
            }

        }
        else if (tb.ID == "TextBox2")
        {
            if (tb.Text == string.Empty)
            {
                Label1.Text = "Please enter input";
            }
            else
            {
                Label1.Text = TextBox1.Text;

            }
        }


Answers (2)