Test Menu

  • Commentary
  • Deals
  • Coupons

Mar 15, 2012

Reset Web Form - ASP.NET VB

Short simple procedure to clear out the textboxes and reset the dropdowns on a page.  Pass in the Page.Controls for example.



    Private Sub ResetForm(ByVal cc As ControlCollection)
        Try
            For Each c As Control In cc
                If TypeOf c Is TextBox Then
                    CType(c, TextBox).Text = String.Empty
                ElseIf TypeOf c Is DropDownList Then
                    CType(c, DropDownList).SelectedIndex = 0
                Else
                    If c.HasControls Then
                        ResetForm(c.Controls)
                    End If
                End If
            Next
        Catch ex As Exception
               ' log an error
        End Try
    End Sub