【问题标题】:Unable to find client side html date control from server side无法从服务器端找到客户端 html 日期控件
【发布时间】:2022-01-03 17:37:05
【问题描述】:

无法从服务器端找到客户端 html 日期控件。

以下html代码用于捕获日期。

<input type="date" class="form-control" id="dtpdob" runat="server" placeholder="Enter Date of Birth" name="dtpdob"  />

服务器端的以下代码用于查找客户端的控制。

Dim btns As HtmlInputText = TryCast(Me.FindControl("dtpdob"), HtmlInputText)
If btns.Value = "" Then
   lblErrorText.Text = "No data available"
End If

系统在 btns.Value 中给出以下错误

System.NullReferenceException: '对象引用未设置为 一个对象的实例。 btns 什么都不是。

请帮忙。

【问题讨论】:

    标签: html asp.net


    【解决方案1】:

    您可以尝试以下方法:

    Dim btns As HtmlInputControl = DirectCast(Me.FindControl("dtpdob"), System.Web.UI.HtmlControls.HtmlInputControl)
        If btns.Value = "" Then
            lblErrorText.Text = "No data available"
        End If
    

    【讨论】:

    • 非常感谢。完成了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-16
    • 2018-02-03
    相关资源
    最近更新 更多