Clear all the control values in webpage
Here is the code to clear all the control values in the page. this function should call on Reset button Click event.
private void ResetFormValues(Control parent)
{
foreach (Control c in parent.Controls)
{
if (c.Controls.Count > 0)
{
ResetFormValues(c);
}
else
{
switch(c.GetType().ToString())
{
case "System.Web.UI.WebControls.TextBox":
((TextBox)c).Text = "";
break;
case "System.Web.UI.WebControls.CheckBox":
((CheckBox)c).Checked = false;
break;
case "System.Web.UI.WebControls.RadioButton":
((RadioButton)c).Checked = false;
break;
}
}
}
}
The same you can do it on JAVASCRIPT
Ex:
<input id="Button1" type='button' onclick='ClearAllControls()' value='Clear All Controls Using Javascript' />
<script language="javascript" type='text/javascript'>
function ClearAllControls() {
for (i = 0; i <>
doc = document.forms[0].elements[i];
switch (doc.type) {
case "text":
doc.value = "";
break;
case "checkbox":
doc.checked = false;
break;
case "radio":
doc.checked = false;
break;
case "select-one":
doc.options[doc.selectedIndex].selected = false;
break;
case "select-multiple":
while (doc.selectedIndex != -1) {
indx = doc.selectedIndex;
doc.options[indx].selected = false;
}
doc.selected = false;
break;
default:
break;
}
}
}
</script>
How to call this on my reset button?