B
BJ
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.EventArgs) Handles cmdReset.Click
'Dim ctrl As Control
'Dim txtBox As TextBox
'Dim crtls As ControlCollection = Me.CreateControlCollection
'For Each ctrl In Me.Controls
' If ctrl.GetType Is GetType(WebControls.TextBox) Then
' DirectCast(ctrl, TextBox).Text = ""
' ElseIf ctrl.GetType Is GetType(WebControls.CheckBox) Then
' ElseIf ctrl.GetType Is GetType(WebControls.DropDownList)
Then
' Else
' 'do nothing
' End If
'Next
'Dim myEnumerator As IEnumerator = Me.Controls.GetEnumerator()
'While (myEnumerator.MoveNext())
' Dim myObject As Object = myEnumerator.Current
' If (myObject.GetType().Equals(GetType(TextBox))) Then
' DirectCast(myObject, TextBox).Text = ""
' End If
'End While
'For Each ctrl In Me.Controls
' If ctrl.GetType.ToString =
GetType(WebControls.TextBox).ToString Then
' DirectCast(ctrl, TextBox).Text = ""
' End If
'Next
'For Each ctrl In Me.CreateControlCollection()
' If ctrl.GetType.ToString =
GetType(WebControls.TextBox).ToString Then
' DirectCast(ctrl, TextBox).Text = ""
' End If
'Next
'For Each ctrl In crtls
' If ctrl.GetType.ToString =
GetType(WebControls.TextBox).ToString Then
' DirectCast(ctrl, TextBox).Text = ""
' End If
'Next
Me.txtDateNeeded.Text = ""
Me.txtName.Text = ""
Me.txtPhone.Text = ""
Me.txtProductName.Text = ""
Me.txtPurchaseQty.Text = ""
Me.txtRecieved.Text = ""
Me.ckbAuthList.Checked = False
Me.ckbOneTimePurchase.Checked = False
Me.ckbStocked.Checked = 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.EventArgs) Handles cmdReset.Click
'Dim ctrl As Control
'Dim txtBox As TextBox
'Dim crtls As ControlCollection = Me.CreateControlCollection
'For Each ctrl In Me.Controls
' If ctrl.GetType Is GetType(WebControls.TextBox) Then
' DirectCast(ctrl, TextBox).Text = ""
' ElseIf ctrl.GetType Is GetType(WebControls.CheckBox) Then
' ElseIf ctrl.GetType Is GetType(WebControls.DropDownList)
Then
' Else
' 'do nothing
' End If
'Next
'Dim myEnumerator As IEnumerator = Me.Controls.GetEnumerator()
'While (myEnumerator.MoveNext())
' Dim myObject As Object = myEnumerator.Current
' If (myObject.GetType().Equals(GetType(TextBox))) Then
' DirectCast(myObject, TextBox).Text = ""
' End If
'End While
'For Each ctrl In Me.Controls
' If ctrl.GetType.ToString =
GetType(WebControls.TextBox).ToString Then
' DirectCast(ctrl, TextBox).Text = ""
' End If
'Next
'For Each ctrl In Me.CreateControlCollection()
' If ctrl.GetType.ToString =
GetType(WebControls.TextBox).ToString Then
' DirectCast(ctrl, TextBox).Text = ""
' End If
'Next
'For Each ctrl In crtls
' If ctrl.GetType.ToString =
GetType(WebControls.TextBox).ToString Then
' DirectCast(ctrl, TextBox).Text = ""
' End If
'Next
Me.txtDateNeeded.Text = ""
Me.txtName.Text = ""
Me.txtPhone.Text = ""
Me.txtProductName.Text = ""
Me.txtPurchaseQty.Text = ""
Me.txtRecieved.Text = ""
Me.ckbAuthList.Checked = False
Me.ckbOneTimePurchase.Checked = False
Me.ckbStocked.Checked = False
End Sub