I’m trying to cycle through the controls on a page that consists of textboxes and a dropdown and clear them.
When I debug, parent is the current page, value is equal to ASP.nameOfCurrentpage_aspx and
Type is equal to system.web.ui.page, but c has the value of ASP.site_master and type of system.web.ui.control. I also put in x to see how many controls it finds and x comes back as 1 even though there are 15 or so textboxes on the page. Is there a way I can force c to have the value of ASP.nameOfCurrentpage_aspx? Or is that not my problem? Any help is appreciated.
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
Thank you every for your help. I didn’t try all of the answers but I used them for ideas. This is what we came up with at work and it finds and clears all the controls on the page. We had to find the content place holder linked to the master site (cph). Again thanks for all the suggestions.