On a site I found the TryParse
method (how to check if there is a empty textbox in C#) but I don't know how to use it.
int outputValue=0;
bool isNumber=false;
isNumber=int.TryParse(textBox1.Text, out outputValue);
if(!isNumber)
{
MessageBox.Show("Type numbers in the textboxes");
}
else
{
// some code
}
and how can i solve this for 1+ number of textboxes
If you want to check empty for all text box control in your page .Try IsNullOrWhiteSpace
foreach (Control child in this.Controls)
{
TextBox textBox = child as TextBox;
if (textBox != null)
{
if (!string.IsNullOrWhiteSpace(textBox.Text))
{
MessageBox.Show("Text box can't be empty");
}
}
}