Server approach
If you want to clear the TextBoxes and DropDownLists from the postback, you can go through the collection Controlsand see for each control whether it is a TextBox or DropDownList. Here's a function in C #:
void ClearInputs(ControlCollection ctrls)
{
foreach (Control ctrl in ctrls)
{
if (ctrl is TextBox)
((TextBox)ctrl).Text = string.Empty;
else if (ctrl is DropDownList)
((DropDownList)ctrl).ClearSelection();
ClearInputs(ctrl.Controls);
}
}
To use this, you call ClearInputspassing in the control collection that you want to execute. To clear all TextBoxes and DropDownLists on the page you are using:
ClearInputs(Page.Controls);
Customer approach
. , JavaScript DOM clear/ reset . JavaScript jQuery library :
function clearElements() {
$("input[type=text]").val('');
$("select").attr('selectedIndex', 0);
}
value <input type="text" ... /> selectedIndex <select> 0. script JSFiddle.net, script: http://jsfiddle.net/xs6G9/
. . WebForm ASP.NET.
!