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

  • 相关阅读:
    Linux_MMU
    Linux_CPU寄存器简介
    Linux_数据段、代码段、堆栈段、BSS段的区别
    Linux_基本使用方法
    Linux_代码段和数据段的定义以及思考
    Linux_虚拟地址、线性地址和物理地址的转换
    Linux_微内核和单内核
    Linux_Linux的分段和分页机制
    教你实现一个朴实的Canvas时钟效果
    OpenMetric与时序数据库模型之主流TSDB分析
  • 原文地址:https://www.cnblogs.com/zhangsongshan/p/3056064.html
Copyright © 2011-2022 走看看