zoukankan      html  css  js  c++  java
  • 本人开发的带提示的TextBox控件

     /// <summary>
        /// created by 章松山 2012-09-20
        /// </summary>
        public class TipTextBox:TextBox
        {
            [Bindable(true)]
            [Category("Appearance")]
            [Localizable(true)]
            public string DefalutText
            {
                get
                {
                    String s = (String)ViewState["DefalutText"];
                    return ((s == null) ? String.Empty : s.Trim());
                }
                set
                {
                    ViewState["DefalutText"] = value;
                }
            }
            public string TipDisplay
            {
                get
                {
                    String s = (String)ViewState["TipDisplay"];
                    return ((s == null) ? "inline" : s.Trim());
                }
                set
                {
                    ViewState["TipDisplay"] = value;
                }
            }
            public string ContentDisplay
            {
                get
                {
                    String s = (String)ViewState["ContentDisplay"];
                    return ((s == null) ? "none" : s.Trim());
                }
                set
                {
                    ViewState["ContentDisplay"] = value;
                }
            }
         
            protected override void RaisePostDataChangedEvent()
            {
                if (!string.IsNullOrEmpty(this.Text))
                {
                    TipDisplay = "none";
                    ContentDisplay = "inline";  
                }
                else
                {
                    TipDisplay = "inline";
                    ContentDisplay = "none";  
                }
                base.RaisePostDataChangedEvent();
            }
            protected override void Render(System.Web.UI.HtmlTextWriter writer)
            {
                string tiponclickstr =GetOnclickStr("spantip");
                writer.Write("<span id=\"spantip" + this.ID + "\" style=\"" + this.Width.ToString() + ";display:" + TipDisplay + "\" onclick=" + tiponclickstr + ">");
                string htmltip = "<input type=\"text\" style=\"" + this.Width.ToString() + ";color:Gray\" value='" + DefalutText + "' id=txtTip" + this.ID + " />";
                writer.Write(htmltip);
                writer.Write("</span>");
                string contentonclickstr = GetOnclickStr("spancontent");
                writer.Write("<span id=\"spancontent" + this.ID + "\" style=\"" + this.Width.ToString() + ";display:"+ContentDisplay+"\">");
                base.Render(writer);
                writer.Write("</span>");
            }
            protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
            {
                this.Attributes.Add("onblur", GetOnclickStr("spancontent"));
                this.Style.Add("width", this.Width.ToString());
                base.AddAttributesToRender(writer);
            }
            private string GetOnclickStr(string htmlkind)
            {
                string str = string.Empty;
                if (htmlkind == "spantip")
                {
                    str = "document.getElementById('spantip" + this.ID + "').style.display='none';";
                    str += "document.getElementById('spancontent" + this.ID + "').style.display='inline';";
                    str += "document.getElementById('"+this.ClientID + "').focus();";
                }
                else
                {
                    str = "if(this.value==''){document.getElementById('spantip" + this.ID + "').style.display='inline';";
                    str += "document.getElementById('spancontent" + this.ID + "').style.display='none';}";      
                }
                return str;
            }
        }

  • 相关阅读:
    『Python基础』第4节:基础数据类型初识
    『Python基础练习题』day02
    『Python基础』第1节 Windows环境下安装Python3.x
    Windows安装Mysql5.7.22
    jar 运行报错:找不到或无法加载主类
    linux 下的mysql 连接报错
    将本地Jar包安装到maven仓库中去
    Mysql 中的伪列用法
    Mysql 中的伪列用法1
    关于springboot中文件上传,properties配置
  • 原文地址:https://www.cnblogs.com/zhangsongshan/p/3056064.html
Copyright © 2011-2022 走看看