TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How to validate all textbox controls of window form application
Shreesh Raj
Jul 21
2016
Code
1.1
k
0
3
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
namespace
ManagementApplication
{
public
partial
class
UserRegistration : Form
{
// public String characters = "abcdeCDEfghijkzMABFHIJKLNOlmnopqrPQRSTstuvwxyUVWXYZ";
public
UserRegistration()
{
InitializeComponent();
}
private
void
UserRegistration_Load(
object
sender, EventArgs e)
{
WindowState = FormWindowState.Maximized;
dateTimePicker1.Format = DateTimePickerFormat.Short;
}
private
void
button1_Click(
object
sender, EventArgs e)
{
TextBox[] text =
new
TextBox[5];
text[0] = textBox1;
text[1] = textBox2;
text[2] = textBox3;
text[3] = textBox4;
text[4] = textBox5;
foreach
( TextBox txt
in
text )
{
if
(txt.Text ==
""
)
{
MessageBox.Show(
"Field Can't be Blank"
);
break
;
}
}
if
(textBox1.Text !=
""
&& textBox2.Text !=
""
&& textBox3.Text !=
""
&& textBox4.Text !=
""
&& textBox5.Text !=
""
)
{
for
(
int
i = 0; i <= 4; i = i + 1)
{
text[i].Text =
""
;
}
MessageBox.Show(
"Your data has been added your data successfully"
);
}
}
}
}
controls
validation
textbox