我正在尝试循环浏览由文本框和下拉菜单组成的页面上的控件并清除它们。
我调试的时候,parent是当前页面,value等于ASP.nameOfCurrentpage_aspx,Type等于system.web.ui.page,但是c的值是ASP.site_master,type是system.web.ui.control。我还输入了 x 以查看它找到了多少控件,并且 x 返回为 1,即使页面上有 15 个左右的文本框。有没有办法可以强制 c 具有 ASP.nameOfCurrentpage_aspx 的值?或者这不是我的问题?任何帮助表示赞赏。
Protected Sub btnClear_Click(sender as Object, e as System.eventargs) Handles btnClear.Click
ClearForm(Page)
End Sub
Public Sub ClearForm(ByRef Parent As Control)
Dim c As Control
Dim x As Integer = Parent.Controls.Count
For Each c In Parent.Controls
If c.GetType.ToString = "System.Web.UI.HtmlControls.HtmlForm" Then
ClearForm(c)
ElseIf c.GetType() Is GetType(TextBox) Then
'is it a Text Box?
Dim t As TextBox = c
t.Text = ""
ElseIf c.GetType() Is GetType(DropDownList) Then
'is it a dropdown list?
Dim d As DropDownList = c
d.ClearSelection()
End If
Next
End Sub