CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2005
    Posts
    73

    textbox validation

    Hi
    I am completely new to c# .so i am just into basics.
    just now i am beginning to work with windows forms

    now i have to add a text box and a insert button
    now when iam entering the text it should be inserted when the button is clicked.
    now wht i need is that when teh text box is empty and when i clicked teh button , it should show a message saying that textbox is empty

    I Think this is very smalll problem. But as ia m new, pls guide me to do it .

    j o h n

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: textbox validation

    This is the code you should write in the Click Event handler of your button
    Code:
    private void button1_Click(object sender, System.EventArgs e)
    {
    	//Check the length of the text
    	if (textBox1.Text.Length == 0 )
    	{
    		//show a message
    		MessageBox.Show ("Textbox cannot be empty");
    		//set focus back to textbox
    		textBox1.Focus();
    	}
    	else
    	{
    		MessageBox.Show ("You entered : " + textBox1.Text);
    	}
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured