Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How to validate all textbox controls of window form application
WhatsApp
Shreesh Raj
Jul 21
2016
1.2
k
0
3
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
Up Next
How to validate all textbox controls of window form application