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;
            }
        }

  • 相关阅读:
    多路径下使用ASMLIB创建ASM磁盘
    linux7.4开启hugepages
    Oracle 12CR2 RAC 升级
    深度思考比勤奋更重要(转)
    Oracle最大保护模式是有延迟的
    mysql主从安装简记
    Socket 监控服务器运行状态
    12C Sharding 学习安装
    惊喜与局限并存,12c Sharding内测报告抢先看!
    Oracle 12c 分片(Sharding)技术
  • 原文地址:https://www.cnblogs.com/zhangsongshan/p/3056064.html
Copyright © 2011-2022 走看看