【问题标题】:if statement to check if the user has left the text box empty - issueif 语句检查用户是否将文本框留空 - 问题
【发布时间】:2023-03-28 08:03:01
【问题描述】:

我有一个带有文本框的 Web 表单,用户可以在其中输入 URL,因此默认情况下我放置了 https://,但如果用户在之后没有输入 URL 并将其留空,我想显示错误。我用过

if (textBox1.TextLength <= 9)
{
    // code
}

【问题讨论】:

    标签: c# if-statement webforms textbox


    【解决方案1】:

    使用具有.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
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-26
      • 2013-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 2011-06-26
      相关资源
      最近更新 更多