代码如下,为什么只取得System.Web.UI.HtmlControls.HtmlForm与
System.Web.UI.LiteralControl这两个控件呢?TextBox与Button为什么没有被取得呢?我已用trace了,显示网页中不止这两个控件呀?大家帮帮忙呀,谢了.<%@ Page Language="VB" Debug="true" Trace="true"%>
<script language="vb" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
    Dim i as Integer
    Response.Write(Controls.Count & "<BR>")
For i = 0 To Controls.Count - 1
    Response.Write(Controls(i).GetType.ToString() & "<BR>")
    Next i
End Sub
</script><Form runat="server">
<asp:TextBox id="TextBox1" runat="server"/>
<asp:Button id="Button1" Text="Button" runat="server"/>
</Form>

解决方案 »

  1.   

    <%@ Page Language="VB" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">Private _obj As Control = Nothing 
    Private ControlID As String = "" Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    GetChildControl(Page)
    Response.Write(ControlID )
      End SubSub GetChildControl(ByVal ParentControl As Control) 
     If ParentControl.HasControls Then 
       For Each ctl As Control In ParentControl.Controls 
         ControlID += "<li>" + ctl.GetType().ToString
         GetChildControl(ctl) 
       Next 
     End If 
    End Sub</script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <title></title>
    </head>
    <body>
      <form id="Form1" runat="server">
        <asp:button id=x runat=server/>
      </form>
    </body>
    </html>