日期:2014-05-17  浏览次数:20389 次

如何判断文本框控件是否存在
前端代码如下:<input id='b1' ReadOnly='true' value='0' style='width:80px;' runat="server" />

我在后台如何判断是否存在 id='b1' 的input?

------解决方案--------------------
遍历页面,标签是input的。。。
------解决方案--------------------
或者form1.FindControl(“id”)看看是不是空
------解决方案--------------------
VB.NET code

        Dim bool As Boolean = False
        For Each item In Me.Controls
            If item.GetType.ToString = "System.Web.UI.HtmlControls.HtmlInputText" Then
                Dim control = TryCast(item, System.Web.UI.HtmlControls.HtmlInputText)
                If control.ID = "b1" Then
                    bool = True
                    Exit For
                End If
            End If
         Next