首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IsNullOrEmpty和IsNullOrWhiteSpace返回"System.Web.UI.HtmlControls.HtmlInputText“

IsNullOrEmpty和IsNullOrWhiteSpace返回"System.Web.UI.HtmlControls.HtmlInputText“
EN

Stack Overflow用户
提问于 2020-05-11 04:31:36
回答 1查看 35关注 0票数 0
代码语言:javascript
复制
        protected void btnAddAppliance(object sender, EventArgs e)
        {
            var description = "";
            var succeeded = true;

            try
            {
                description = Convert.ToString(iptDescription);
                if (string.IsNullOrEmpty(description) || string.IsNullOrWhiteSpace(description))
                {
                    errormessage.Text = "You need to add a description!";
                    errormessage.Visible = true;
                    succeeded = false;
                }
            }
            catch
            {
                errormessage.Text = "Enter a correct description!";
                errormessage.Visible = true;
                succeeded = false;
            }

            if (succeeded)
            {
                _c.NewAppliance(description);
                grvAppliances.DataSource = _c.GetAllAppliances();
                grvAppliances.DataBind();
                iptDescription.Value = "";
            }
        }

你好,我的代码有问题。这段代码使用IsNullOrEmpty()IsNullOrWhiteSpace()方法检查我输入的值值是否不为空或不包含任何空格。每次我将输入留空时,它都会返回"System.Web.UI.HtmlControls.HtmlInputText",并将其放入我的MySQL数据库中,而不是提示我输入的错误消息。我该如何解决这个问题呢?

EN

回答 1

Stack Overflow用户

发布于 2020-05-11 04:44:13

您需要按照注释中的建议使用html控件元素的Value属性。因此,您应该使用Convert.ToString(iptDescription.Value)而不是Convert.ToString(iptDescription)

此外,除非被覆盖,否则ToString()将返回该类型的完全限定名。在本例中,HTML控件元素HtmlInputText

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61718331

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档