title: Best practice when overriding Render methods on Asp.net WebControls, UserControls, Controls
body: <p>When creating a custom <code>WebControl</code>, <code>UserControl</code>, <code>Control</code> and there is the need to override the various Render methods there are mainly 2 way to accomplish this:</p>
  
  <p>the quick and dirty:</p>
  
  <pre><code>public override void RenderControl(HtmlTextWriter writer)
  {
      writer.Write("&lt;div class=\"{0}\"&gt;&lt;a href={1}&gt;{2}&lt;/a&gt;", CssClass, "/someurl.aspx", LocalizedStrings.EditLinkText);
      base.RenderControl(writer);
      writer.Write("&lt;/div&gt;");
  }
  </code></pre>
  
  <p>the long and clean:</p>
  
  <pre><code>public override void RenderControl(HtmlTextWriter writer)
  {
      writer.WriteBeginTag(HtmlTextWriterTag.Div.ToString());
      writer.WriteAttribute(HtmlTextWriterAttribute.Class.ToString(), CssClass);
      writer.Write(HtmlTextWriter.TagRightChar);
      var link = new HtmlAnchor();
      link.HRef = "/someurl.aspx";
      link.Title = LocalizedStrings.EditLinkTitle;
      link.InnerText = LocalizedStrings.EditLinkText; ;
      link.Attributes.Add(HtmlTextWriterAttribute.Class.ToString(), "someclass");
      link.RenderControl(writer);
      base.RenderControl(writer);
      writer.WriteEndTag(HtmlTextWriterTag.Div.ToString());
  }
  </code></pre>
  
  <p>I was wondering if the second method was worth it.</p>