【发布时间】:2023-03-28 08:03:01
【问题描述】:
我有一个带有文本框的 Web 表单,用户可以在其中输入 URL,因此默认情况下我放置了 https://,但如果用户在之后没有输入 URL 并将其留空,我想显示错误。我用过
if (textBox1.TextLength <= 9)
{
// code
}
【问题讨论】:
标签: c# if-statement webforms textbox
我有一个带有文本框的 Web 表单,用户可以在其中输入 URL,因此默认情况下我放置了 https://,但如果用户在之后没有输入 URL 并将其留空,我想显示错误。我用过
if (textBox1.TextLength <= 9)
{
// code
}
【问题讨论】:
标签: c# if-statement webforms textbox
使用具有.Text 属性的相等运算符代替Length 检查,以检查文本框中的确切文本。
//This means, there is only "https://" is written in the text box
if(textBox1.Text == "https://")
{
//Show an error. Here user did not enter anything
}
else
{
//Your implementation
}
【讨论】: