如何检查文本框是否为空

2024-02-17

在一个网站上我发现了TryParse方法(如何检查C#中是否有空文本框)但我不知道如何使用它。

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
}

我该如何解决 1 个以上文本框的问题


如果您想为页面中的所有文本框控件检查为空。尝试为空或空白 http://msdn.microsoft.com/en-us/library/system.string.isnullorwhitespace%28v=vs.110%29.aspx

 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");
            }
        }
    }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何检查文本框是否为空 的相关文章

随机推荐