title: hiding div element in code behind
body: <p>I have built a slideshow. Each of the slides has a div placed over the top of it. The div contains some text. What I want to do is if the <code>h2</code> and <code>p</code> element have no text then hide the div that contains them. I have attempted to hide the div from the repeaters DataBound event but it is still showing the div over the slide.</p>
  
  <p>Here's what I have so far:</p>
  
  <p>aspx:</p>
  
  <pre><code>&lt;asp:Repeater ID="rptSlides" runat="server" ClientIDMode="Static" OnItemDataBound="rptSlides_ItemDataBound"&gt;
      &lt;ItemTemplate&gt;
          &lt;div runat="server" id="slideDiv" class="slide"&gt;
              &lt;img runat="server" src='&lt;%# Eval("slideImgPath")%&gt;' /&gt;
              &lt;div id="slideTextdiv" runat="server" class="slideText"&gt;
                  &lt;h2 id="titlePlaceHolder" runat="server" class="slideTitle text-center text-capitalize h2 "&gt;
                      &lt;%# Eval("slideTitle") %&gt;
                  &lt;/h2&gt;
                  &lt;p id="textPlaceHolder" runat="server" class="slideDes"&gt;
                      &lt;%# Eval("slideDesc") %&gt;
                  &lt;/p&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:Repeater&gt;
  </code></pre>
  
  <p>Code behind:</p>
  
  <pre><code> protected void rptSlides_ItemDataBound(object sender, RepeaterItemEventArgs e)
  {
      foreach (RepeaterItem item in rptSlides.Items)
      {
          HtmlGenericControl titleText = (HtmlGenericControl)item.FindControl("titlePlaceHolder");
          HtmlGenericControl slidetextDesc = (HtmlGenericControl)item.FindControl("textPlaceHolder");
          HtmlGenericControl slideDiv = (HtmlGenericControl)item.FindControl("slideTextdiv");
  
          if (titleText.InnerText == "" &amp;&amp; slidetextDesc.InnerText == "")
          {
              slideDiv.Style.Add("Display", "none");                
          }
      }
  }
  </code></pre>
  
  <p><strong>Further info</strong></p>
  
  <p>I have also tried the following:</p>
  
  <pre><code>foreach (RepeaterItem item in rptSlides.Items)
      {
          HtmlGenericControl slideDiv = (HtmlGenericControl)FindControlRecursive(item, "slideTextdiv");
          HtmlGenericControl titleText = (HtmlGenericControl)FindControlRecursive(item, "titlePlaceHolder");
          HtmlGenericControl slidetextDesc = (HtmlGenericControl)FindControlRecursive(item, "textPlaceHolder");
  
  
          if (string.IsNullOrWhiteSpace(titleText.InnerText) &amp;&amp; string.IsNullOrWhiteSpace(slidetextDesc.InnerText))
          {
              slideDiv.Attributes["class"] = "emptySlideText";
          }
      }
  </code></pre>
  
  <p>I created a class in the css called emptySlideText, like so:</p>
  
  <pre><code>.emptySlideText {
  display:none; }
  </code></pre>
  
  <p>Unfortunatley this has had no effect.</p>
  
  <p>I have also tried changing the line </p>
  
  <p>slideDiv.Style.Add("Display", "none");</p>
  
  <p>to </p>
  
  <p>slideDiv.Attributes.Add("style", "display:none");</p>
  
  <p>But again it made no difference</p>