views:

73

answers:

1

Retrofitting ASP.NET WebForms themes to an old application I have a need to theme an <input> tag such that the JavaScript click event is different for each theme. I replaced with tag with an asp:Button, only to disciver that the OnClientClick property is not themeable.

Can anyone suggest a workaround for this?

+1  A: 

ThemeableButton

You have to create a simple class that derived from Button. Then override the OnClientClick property and add a Themeable attribute to as follows.

[ToolboxData("<{0}:Button runat=\"server\" />")]
public class ThemeableButton : Button
{

    [Themeable(true)]
    public override string OnClientClick
    {
        get { return base.OnClientClick; }
        set { base.OnClientClick = value; }
    }

}

Web.Config

Now, you have to replace the old button with new one. Change the pages section as follows.

<pages>
  <tagMapping>
    <add tagType="System.Web.UI.WebControls.Button, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
         mappedTagType="[Namespace].ThemeableButton, [AssemblyName]" />
  </tagMapping>
</pages>
Mehdi Golchin