// XamlButton.ascx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class XamlButton : System.Web.UI.UserControl
{

  const string loadedScript = @"
    function {0}(sender, args) {{
      setupButton(sender, {1});
    }}";

  protected void Page_Load(object sender, EventArgs e)
  {
    // Setup the shared XAML Script
    Page.ClientScript.RegisterClientScriptInclude(this.GetType(), 
                                                  "XAMLBUTTON.JS", 
                                                  "js/XamlButton.js");

    // Add Button Script 
    string script = string.Format(loadedScript, LoadedFunctionName, ClickHandler.Length > 0 ? ClickHandler : "null");
    string key = string.Format("{0}_BUTTONSETUP", Name);
    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), key, script, true);
  }

  string _name;
  int _width = 100;
  int _height = 25;
  int _top = 0;
  int _left = 0;
  string _text = "";
  string _clickHandler = "";
  int _fontSize = 14;

  public string Name
  {
    get { return _name; }
    set { _name = value; }
  }

  public string LoadedFunctionName
  {
    get { return string.Concat(Name, "_Loaded"); }
  }

  public int Width
  {
    set { _width = value; }
    get { return _width; }
  }

  public int Height
  {
    set { _height = value; }
    get { return _height; }
  }

  public int Top
  {
    set { _top = value; }
    get { return _top; }
  }

  public int Left
  {
    set { _left = value; }
    get { return _left; }
  }

  public string Text
  {
    set { _text = value; }
    get { return _text; }
  }

  public string ClickHandler
  {
    set { _clickHandler = value; }
    get { return _clickHandler; }
  }

  public int FontSize
  {
    set { _fontSize = value; }
    get { return _fontSize; }
  }
}
