I am trying to loop through the control collection of my ASP.NET web
form in order to access the contents of each field.
It seems as if there is a parent control (Literal?) in ASP.NET.
Attached are my failed attemps as well as the
hardcoded lines that do work.
TIA
Private Sub cmdReset_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdReset.Click
'Dim ctrl As Control
'Dim txtBox As TextBox
'Dim crtls As ControlCollecti on = Me.CreateContro lCollection
'For Each ctrl In Me.Controls
' If ctrl.GetType Is GetType(WebCont rols.TextBox) Then
' DirectCast(ctrl , TextBox).Text = ""
' ElseIf ctrl.GetType Is GetType(WebCont rols.CheckBox) Then
' ElseIf ctrl.GetType Is GetType(WebCont rols.DropDownLi st)
Then
' Else
' 'do nothing
' End If
'Next
'Dim myEnumerator As IEnumerator = Me.Controls.Get Enumerator()
'While (myEnumerator.M oveNext())
' Dim myObject As Object = myEnumerator.Cu rrent
' If (myObject.GetTy pe().Equals(Get Type(TextBox))) Then
' DirectCast(myOb ject, TextBox).Text = ""
' End If
'End While
'For Each ctrl In Me.Controls
' If ctrl.GetType.To String =
GetType(WebCont rols.TextBox).T oString Then
' DirectCast(ctrl , TextBox).Text = ""
' End If
'Next
'For Each ctrl In Me.CreateContro lCollection()
' If ctrl.GetType.To String =
GetType(WebCont rols.TextBox).T oString Then
' DirectCast(ctrl , TextBox).Text = ""
' End If
'Next
'For Each ctrl In crtls
' If ctrl.GetType.To String =
GetType(WebCont rols.TextBox).T oString Then
' DirectCast(ctrl , TextBox).Text = ""
' End If
'Next
Me.txtDateNeede d.Text = ""
Me.txtName.Text = ""
Me.txtPhone.Tex t = ""
Me.txtProductNa me.Text = ""
Me.txtPurchaseQ ty.Text = ""
Me.txtRecieved. Text = ""
Me.ckbAuthList. Checked = False
Me.ckbOneTimePu rchase.Checked = False
Me.ckbStocked.C hecked = False
End Sub
form in order to access the contents of each field.
It seems as if there is a parent control (Literal?) in ASP.NET.
Attached are my failed attemps as well as the
hardcoded lines that do work.
TIA
Private Sub cmdReset_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdReset.Click
'Dim ctrl As Control
'Dim txtBox As TextBox
'Dim crtls As ControlCollecti on = Me.CreateContro lCollection
'For Each ctrl In Me.Controls
' If ctrl.GetType Is GetType(WebCont rols.TextBox) Then
' DirectCast(ctrl , TextBox).Text = ""
' ElseIf ctrl.GetType Is GetType(WebCont rols.CheckBox) Then
' ElseIf ctrl.GetType Is GetType(WebCont rols.DropDownLi st)
Then
' Else
' 'do nothing
' End If
'Next
'Dim myEnumerator As IEnumerator = Me.Controls.Get Enumerator()
'While (myEnumerator.M oveNext())
' Dim myObject As Object = myEnumerator.Cu rrent
' If (myObject.GetTy pe().Equals(Get Type(TextBox))) Then
' DirectCast(myOb ject, TextBox).Text = ""
' End If
'End While
'For Each ctrl In Me.Controls
' If ctrl.GetType.To String =
GetType(WebCont rols.TextBox).T oString Then
' DirectCast(ctrl , TextBox).Text = ""
' End If
'Next
'For Each ctrl In Me.CreateContro lCollection()
' If ctrl.GetType.To String =
GetType(WebCont rols.TextBox).T oString Then
' DirectCast(ctrl , TextBox).Text = ""
' End If
'Next
'For Each ctrl In crtls
' If ctrl.GetType.To String =
GetType(WebCont rols.TextBox).T oString Then
' DirectCast(ctrl , TextBox).Text = ""
' End If
'Next
Me.txtDateNeede d.Text = ""
Me.txtName.Text = ""
Me.txtPhone.Tex t = ""
Me.txtProductNa me.Text = ""
Me.txtPurchaseQ ty.Text = ""
Me.txtRecieved. Text = ""
Me.ckbAuthList. Checked = False
Me.ckbOneTimePu rchase.Checked = False
Me.ckbStocked.C hecked = False
End Sub
Comment