Fuction to clear all the controls of the page.

Posted by Virendradugar under VB.NET category on | Views : 2465
Use this function to reset textbox, dropdownlist and checkbox. You can extend this function for other controls also.

Kindly note: I have used Me.Controls to search the controls but this can change, if you have used Master pages or all your controls are placed in update panel using master page.

For Each objControls As Control In Me.Controls
If TypeOf objControls Is TextBox Then
CType(objControls, TextBox).Text = String.Empty
End If
If TypeOf objControls Is DropDownList Then
If Not CType(objControls, DropDownList).ID.Contains("ddlUSTYear") Then
CType(objControls, DropDownList).SelectedIndex = 0
End If
End If
If TypeOf objControls Is CheckBox Then
CType(objControls, CheckBox).Checked = False
End If
If TypeOf objControls Is RadioButton Then
CType(objControls, RadioButton).Checked = False
End If


Comments or Responses

Login to post response