using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using JuSNS.Common;

namespace JuSNS.UI.Control
{
    [DefaultProperty("Text"), ToolboxData("<{0}:JuSNSTextBox runat=server></{0}:JuSNSTextBox>"), Designer("System.Web.UI.Design.WebControls.PreviewControlDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
    public class JuSNSTextBox : System.Web.UI.WebControls.TextBox 
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public JuSNSTextBox(): base()
        {
            base.Attributes.Add("onfocus", "this.className='" + _onFocusCss + "';");
            base.Attributes.Add("onblur", "this.className='" + _onBlurCss + "';");
            base.CssClass = _Class;
        }

        private string _onFocusCss = "colorfocus";
        [Bindable(true), Category("Appearance"), Description("文本框获取焦点时触发的事件")]
        /// <summary>
        /// 获取焦点时样式
        /// </summary>
        public string onFocus
        {
            get { return _onFocusCss; }
            set { _onFocusCss = value; }
        }

        private string _onBlurCss = "colorblur";
        [Bindable(true), Category("Appearance"), Description("文本框失去焦点时触发的事件")]
        /// <summary>
        /// 失去焦点时样式
        /// </summary>
        public string onBlurCss
        {
            get { return _onBlurCss; }
            set { _onBlurCss = value; }
        }

        private string _Class = "colorblur";
        [Bindable(true), Category("Appearance"), DefaultValue("")]
        /// <summary>
        /// 样式
        /// </summary>
        public string Class
        {
            get { return _Class; }
            set { _Class = value; }
        }

        /// <summary>
        /// 获取焦点的控件ID(如提交按钮等)
        /// </summary>
        [Bindable(true), Category("Appearance"), DefaultValue("")]
        public string SetFocusButtonID
        {
            get
            {
                object o = ViewState[this.ClientID + "_SetFocusButtonID"];
                return (o == null) ? "" : o.ToString();
            }
            set
            {
                ViewState[this.ClientID + "_SetFocusButtonID"] = value;
                if (value != "")
                {
                    this.Attributes.Add("onkeydown", "if(event.keyCode==13){document.getElementById('" + value + "').focus();}");
                }
            }
        }



    }
}
