title: Adding Html from Code Behind in Asp.net
body: <p>I want to add HTML structure and control like this from code behind into a panel</p>
  
  <pre><code>&lt;div class='Main'&gt;
      &lt;div class='cst'&gt;
          First Name
      &lt;/div&gt;
      &lt;div class='csc'&gt;
          &lt;asp:Label ID="lblFirstName" CssClass="ronly" runat="server"&gt;&lt;/asp:Label&gt;
      &lt;/div&gt;
      &lt;div class='cst'&gt;
          First Name
      &lt;/div&gt;
      &lt;div class='csc'&gt;
          &lt;asp:Label ID="lblFirstName" CssClass="ronly" runat="server"&gt;&lt;/asp:Label&gt;
      &lt;/div&gt;        &lt;div class='cst'&gt;
          First Name
      &lt;/div&gt;
      &lt;div class='csc'&gt;
          &lt;asp:Label ID="lblFirstName" CssClass="ronly" runat="server"&gt;&lt;/asp:Label&gt;
      &lt;/div&gt;
      &lt;div class='end'&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
    &lt;asp:Panel runat="server" CssClass="sxpnl" ID="pnlUserdata"&gt;
          &lt;/asp:Panel&gt;
  </code></pre>
  
  <p>If i try to add like this</p>
  
  <pre><code> HtmlGenericControl divcontrol = new HtmlGenericControl();
   divcontrol.Attributes["class"] = "sxro sx1co";
   divcontrol.TagName = "div";
   pnlUserSearch.Controls.Add(divcontrol);
   Label question = new Label();
   questionDescription.Text = "text";
   pnlUserSearch.Controls.Add(question);
  </code></pre>
  
  <p>It will add controls one after another, how can i make controls go nested like that as shown above.</p>