日期:2014-05-19  浏览次数:20362 次

想取得一页中所有控件的类型,为什么取得不全呢?
代码如下,为什么只取得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>



------解决方案--------------------
你应当继续遍历子控件。你目前只是循环了一层