title: extending asp.net ImageButton to css Sprite
body: <p>I'm updating my ImageButtons on my asp.net application to a WebControl that extends the ImageButton, which I called CSSImageButton. I've overridden the render methods so I can make them work with css sprites. I've managed to get the OnClick working and the OnClientClick. But some buttons have the OnCommand, and I can't figure out what to do. </p>
  
  <pre><code> public class CSSImageButton : ImageButton
  {
      public string DivClass { get; set; }
  
  
      public CSSImageButton()
      {
          CssClass = "";
      }
  
      protected override void Render(HtmlTextWriter writer)
      {
          base.Render(writer);
      }
  
      public override void RenderBeginTag(HtmlTextWriter writer)
      {
          writer.Write("&lt;div class=\"" + CssClass + " " + DivClass + "\"&gt;");
      }
  
  
      protected override void RenderContents(HtmlTextWriter writer)
      {
          writer.Write("&lt;a id=\"" + this.ClientID + "\" title=\""+ this.ToolTip+"\"");
          if (!String.IsNullOrEmpty(OnClientClick))
          {
              writer.Write(" href=\"javascript:void(0);\" OnClick = \"" + OnClientClick + "\"");
          }
          else
          {
              writer.Write(" href=\"javascript:" + this.Page.GetPostBackEventReference(this, "ButtonClick") + "\"");
          }
          writer.Write("\"&gt;&lt;/a&gt;");
      }
  
      public override void RenderEndTag(HtmlTextWriter writer)
      {
          writer.Write("&lt;/div&gt;");
      }
  
  }
  </code></pre>