Guest User

Untitled

a guest
Jan 17th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. foreach(Label l in Controls) // setting all labels' s visbility on page to true
  2. l.Visible =true;
  3.  
  4. private void SetVisibility<T>(Control parent, bool isVisible)
  5. {
  6. foreach (Control ctrl in parent.Controls)
  7. {
  8. if(ctrl is T)
  9. ctrl.Visible = isVisible;
  10. SetVisibility<T>(ctrl, isVisible);
  11. }
  12. }
  13.  
  14. SetVisibility<Label>(Page, true);
  15.  
  16. foreach(Label l in Controls.OfType<Label>())
  17. {
  18. l.Visible = true;
  19. }
  20.  
  21. foreach(control l in Controls) {
  22. if(l is System.Web.UI.WebControls.Label)
  23. l.Visible = true;
  24. }
  25.  
  26. foreach(Control l in Controls)
  27. if (l is Label) l.Visible =true;
  28.  
  29. public static void SetAllControls( Type t, Control parent /* can be Page */)
  30. {
  31. foreach (Control c in parent.Controls)
  32. {
  33. if (c.GetType() == t) c.Visible=true;
  34. if (c.HasControls()) GetAllControls( t, c);
  35. }
  36.  
  37. }
  38.  
  39. SetAllControls( typeof(Label), this);
  40.  
  41. public void Search(Control control)
  42. {
  43. foreach (Control c in control.Controls)
  44. {
  45. if (c.Controls.Count > 0)
  46. Search(c);
  47. if (c is Label)
  48. c.Visible = false;
  49. }
  50. }
  51.  
  52. Search(this.Page);
Add Comment
Please, Sign In to add comment