Checking textbox is empty or not

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ravipatil
    New Member
    • Sep 2006
    • 1

    Checking textbox is empty or not

    hi

    i am adding two numbers in C#.net & i want to check wheather first textbox is empty or not. if empty, then it must display "enter the first number" otherwise value is stored in first textbox1. Similarly for second textbox. and the sum of two numbers is stored third textbox.

    thank you,
  • anaphaxeon
    New Member
    • Oct 2006
    • 30

    #2
    private int Number1 = 0;
    private int Number2 = 0;


    protected internal void AddNumbers()
    {
    ValidateForm();
    this.TextBox3.T ext = Convert.ToStrin g(Number1 + Number2);
    }
    protected internal void ValidateForm()
    {
    try
    {
    Number1 = Convert.ToInt32 (this.TextBox1. Text);
    }
    catch
    {
    MessageBox.Show ("Please enter a valid number 1!");
    this.TextBox1.F ocus();
    this.TextBox1.S electAll();
    }
    try
    {
    Number2 = Convert.ToInt32 (this.TextBox2. Text);
    }
    catch
    {
    MessageBox.Show ("Please enter a valid number 2!");
    this.TextBox2.F ocus();
    this.TextBox2.S electAll();
    }
    }

    Comment

    Working...