.NET Control.ID属性不一致

时间:2013-02-05 21:21:43

标签: asp.net vb.net

请查看以下代码:

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim c1 As New CheckBox
        c1.ID = "Test1/" 'line 7
        PlaceHolder1.Controls.Add(c1)
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        For Each c As Control In Page.Controls
            For Each d As Control In c.Controls
                For Each f As Control In d.Controls
                    For Each g As Control In f.Controls
                        For Each h As Control In g.Controls
                            If TypeOf h Is CheckBox Then
                                Dim cbox As New CheckBox
                                cbox = CType(h, CheckBox)
                                MsgBox(cbox.Checked) 'Line 20
                            End If
                        Next
                    Next
                Next
            Next
        Next
    End Sub
End Class

default.aspx页面上有一个占位符:PlaceHolder1。第20行的MessageBox正在打印True。请查看以下网页中引用的引用:http://msdn.microsoft.com/en-us/library/system.web.ui.control.id.aspx

  

“仅包含字母数字字符和下划线的组合   character(_)是此属性的有效值。包括空格   或其他无效字符将导致ASP.NET页面解析器错误。“

/不是字母数字字符,因此消息框如何打印为true?如果将第7行更改为:c1.ID = "Test1:",则会按照我的预期打印错误(因为:(冒号)是非字母数字)。没有一致性。我错过了什么。

0 个答案:

没有答案