|
-
July 20th, 2005, 04:00 AM
#1
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
-
July 20th, 2005, 04:27 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|