views:

337

answers:

0

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.

 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("<div class=\"" + CssClass + " " + DivClass + "\">");
    }


    protected override void RenderContents(HtmlTextWriter writer)
    {
        writer.Write("<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("\"></a>");
    }

    public override void RenderEndTag(HtmlTextWriter writer)
    {
        writer.Write("</div>");
    }

}