Guest User

Untitled

a guest
Mar 24th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. <script>
  2. $(':input').each(function () {
  3. switch (this.type) {
  4. case 'password':
  5. case 'text':
  6. case 'select-multiple':
  7. case 'select-one':
  8. case 'textarea':
  9. $(this).val('');
  10. break;
  11. case 'checkbox':
  12. case 'radio':
  13. this.checked = false;
  14. break;
  15. }
  16. });
  17. </script>
  18.  
  19. ClearForm(Page.Form.Controls);
  20.  
  21. public void ClearForm(ControlCollection controls)
  22. {
  23. foreach (Control c in controls)
  24. {
  25. if (c.GetType() == typeof(System.Web.UI.WebControls.TextBox))
  26. {
  27. System.Web.UI.WebControls.TextBox t = (System.Web.UI.WebControls.TextBox)c;
  28. t.Text = String.Empty;
  29. }
  30. //... test for other controls in your forms DDL, checkboxes, etc.
  31.  
  32. if (c.Controls.Count > 0) ClearForm(c.Controls);
  33. }
  34. }
  35.  
  36. foreach (Control i in Page.Form.GetAllChildren())
  37. {
  38. if (i.GetType() == typeof(System.Web.UI.WebControls.TextBox))
  39. {
  40. System.Web.UI.WebControls.TextBox t = (System.Web.UI.WebControls.TextBox)i;
  41. t.Text = String.Empty;
  42. }
  43. // check other types
  44. }
  45.  
  46. public static void ClearFields(ControlCollection pageControls)
  47. {
  48. foreach (Control contl in pageControls)
  49. {
  50. string strCntName = (contl.GetType()).Name;
  51.  
  52. switch (strCntName)
  53. {
  54. case "TextBox":
  55. TextBox tbSource = (TextBox)contl;
  56. tbSource.Text = "";
  57. break;
  58. case "RadioButtonList":
  59. RadioButtonList rblSource = (RadioButtonList)contl;
  60. rblSource.SelectedIndex = -1;
  61. break;
  62. case "DropDownList":
  63. DropDownList ddlSource = (DropDownList)contl;
  64. ddlSource.SelectedIndex = -1;
  65. break;
  66. case "ListBox":
  67. ListBox lbsource = (ListBox)contl;
  68. lbsource.SelectedIndex = -1;
  69. break;
  70. }
  71. ClearFields(contl.Controls);
  72. }
  73. }
  74. protected void btn_cancel_Click(object sender, EventArgs e)
  75. {
  76. ClearFields(Form.Controls);
  77. }
  78.  
  79. ClearFields(Page.Form.Controls);
Add Comment
Please, Sign In to add comment