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

  • 相关阅读:
    Vue项目根据不同运行环境打包项目
    [Vue CLI 3] @vue/cli-plugin-eslint 源码分析
    [Vue CLI 3] 插件开发中的 genCacheConfig 细节研究
    [Vue CLI 3] 配置解析之 parallel
    [Vue CLI 3] 配置 webpack-bundle-analyzer 插件
    [Vue CLI 3] 插件开发之 registerCommand 到底做了什么
    [Vue CLI 3] Uglify 相关的应用和设计
    [Vue CLI 3] vue inspect 的源码设计实现
    [Vue CLI 3] 配置解析之 indexPath
    [Vue CLI 3] 配置解析之 css.extract
  • 原文地址:https://www.cnblogs.com/zhangsongshan/p/3056064.html
Copyright © 2011-2022 走看看