title: div visible false in server side using div class in c#
body: <p>I have a div in  aspx page given below. I have a page that contains the desktop and mobile code and style. I want to show show hide div according to condition. using id (more than 50 div on page) this increase the code and id, using class that is provided above "desktop and "mobile" reduce the code.</p>
  
  <pre><code>&lt;div class="desktop" runat="server"&gt;
              &lt;p&gt;this desktop version1&lt;/p&gt;
          &lt;/div&gt;
          &lt;div class="Mobile" runat="server"&gt;
              &lt;p&gt;this mobile version1&lt;/p&gt;
          &lt;/div&gt;
          &lt;div class="desktop" runat="server"&gt;
              &lt;p&gt;this desktop version1&lt;/p&gt;
          &lt;/div&gt;
          &lt;div class="Mobile" runat="server"&gt;
              &lt;p&gt;this mobile version1&lt;/p&gt;
          &lt;/div&gt;
          &lt;div class="desktop" runat="server"&gt;
              &lt;p&gt;this desktop version1&lt;/p&gt;
          &lt;/div&gt;
          &lt;div class="Mobile" runat="server"&gt;
              &lt;p&gt;this mobile version1&lt;/p&gt;
          &lt;/div&gt;
          &lt;div class="desktop" runat="server"&gt;
              &lt;p&gt;this desktop version1&lt;/p&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>I want to show hide div using div class (not div id) in server side. </p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
      {
  
      }
  </code></pre>
  
  <p>Finally i find solution of this, If any query regarding this please reply. </p>
  
  <pre><code> protected void Page_Load(object sender, EventArgs e)
      {
     string theClass;
     theClass = "desktop";
          var theControls = FindByClass(theClass);
          foreach (Control item in theControls)
          {
              //do something;
              if (item is WebControl)
              {
                  ((WebControl)item).Visible = false;
              }
              else
              {
                 ((HtmlControl)item).Visible = false;
              }
          }
  
      }
  
      private IEnumerable FindByClass(string theClass)
      {
          Control[] allControls = FlattenHierachy(Page);
  
  
          var theControls = from n in allControls
                            where ((n is WebControl)
                            &amp;&amp; ((WebControl)n).CssClass.Contains(theClass))
                            || (n is HtmlControl
                                &amp;&amp; ((HtmlControl)n).Attributes.Count &gt; 0
                                &amp;&amp; ((HtmlControl)n).Attributes["class"] != null
                                &amp;&amp; ((HtmlControl)n).Attributes["class"].IndexOf(theClass) &gt; -1)
                            select n;
          return theControls;
      }
  
      public static Control[] FlattenHierachy(Control root)
      {
          List&lt;Control&gt; list = new List&lt;Control&gt;();
          list.Add(root);
          if (root.HasControls())
          {
              foreach (Control control in root.Controls)
              {
                  list.AddRange(FlattenHierachy(control));
              }
          }
          return list.ToArray();
      }
  </code></pre>