Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- $(':input').each(function () {
- switch (this.type) {
- case 'password':
- case 'text':
- case 'select-multiple':
- case 'select-one':
- case 'textarea':
- $(this).val('');
- break;
- case 'checkbox':
- case 'radio':
- this.checked = false;
- break;
- }
- });
- </script>
- ClearForm(Page.Form.Controls);
- public void ClearForm(ControlCollection controls)
- {
- foreach (Control c in controls)
- {
- if (c.GetType() == typeof(System.Web.UI.WebControls.TextBox))
- {
- System.Web.UI.WebControls.TextBox t = (System.Web.UI.WebControls.TextBox)c;
- t.Text = String.Empty;
- }
- //... test for other controls in your forms DDL, checkboxes, etc.
- if (c.Controls.Count > 0) ClearForm(c.Controls);
- }
- }
- foreach (Control i in Page.Form.GetAllChildren())
- {
- if (i.GetType() == typeof(System.Web.UI.WebControls.TextBox))
- {
- System.Web.UI.WebControls.TextBox t = (System.Web.UI.WebControls.TextBox)i;
- t.Text = String.Empty;
- }
- // check other types
- }
- public static void ClearFields(ControlCollection pageControls)
- {
- foreach (Control contl in pageControls)
- {
- string strCntName = (contl.GetType()).Name;
- switch (strCntName)
- {
- case "TextBox":
- TextBox tbSource = (TextBox)contl;
- tbSource.Text = "";
- break;
- case "RadioButtonList":
- RadioButtonList rblSource = (RadioButtonList)contl;
- rblSource.SelectedIndex = -1;
- break;
- case "DropDownList":
- DropDownList ddlSource = (DropDownList)contl;
- ddlSource.SelectedIndex = -1;
- break;
- case "ListBox":
- ListBox lbsource = (ListBox)contl;
- lbsource.SelectedIndex = -1;
- break;
- }
- ClearFields(contl.Controls);
- }
- }
- protected void btn_cancel_Click(object sender, EventArgs e)
- {
- ClearFields(Form.Controls);
- }
- ClearFields(Page.Form.Controls);
Add Comment
Please, Sign In to add comment