惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 司徒正美
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research
Last Week in AI
Last Week in AI
爱范儿
爱范儿
WordPress大学
WordPress大学
V
V2EX
宝玉的分享
宝玉的分享
小众软件
小众软件
B
Blog
博客园 - 叶小钗
U
Unit 42
酷 壳 – CoolShell
酷 壳 – CoolShell
人人都是产品经理
人人都是产品经理
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
H
Help Net Security
P
Proofpoint News Feed
D
Docker
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
月光博客
月光博客

博客园 - 子游

Flash / Flex Tutorial – How to Create a crossdomain.xml file javascript 跨越解决方案 Google OAuth 简单入门与使用 Complete Date Object Reference 速强软件 什么是邮件营销 server variables Oracle 笔记 日期处理 如何配置IIS7的Custom Handlers? 分布式系统设计实践 多线程更新Processbar 什么是在线互动营销 导入CSV文件进入系统 - 子游 - 博客园 如何用asp.net做一个图片handler javascript 的 Encode,Javascript,escape,encodeURI,encodeURIComponent,UTF-8 www.sugaroa.com超酷的新一代协同办公自动化系统 超酷的新一代协同办公自动化系统 什么是Rss feed 正确检查上传文件类型或者get mine type from file Sql server 国际化的支持,查询乱码
开发自定义控件 ------------Textbox 控件(1)
子游 · 2009-08-21 · via 博客园 - 子游

                                    

开发自定义控件 __Textbox控件(1)
  支持postback
   public cass SugaroaInput : WebControl
  {

        private static readonly object EventTextChanged = new object();

        //支持事件
        public event EventHandler TextChanged
        {
            add
            {
                base.Events.AddHandler(EventTextChanged, value);
            }
            remove
            {
                base.Events.RemoveHandler(EventTextChanged, value);
            }
        }

       //post back
        protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection)
        {

            //Page.ClientScript.ValidateEvent(postDataKey, string.Empty);  
            string text = this.Text;
            string str2 = postCollection[postDataKey];
            if (!this.ReadOnly && !text.Equals(str2, StringComparison.Ordinal))
            {
                this.Text = str2;
                return true;
            }
            return false;
        }
    
      //输出html  

      protected override void Render(HtmlTextWriter writer)
        {
            if (Page != null)
                Page.VerifyRenderingInServerForm(this);
             writer.Write("<input ");
            writer.WriteAttribute("type", "input");
            writer.WriteAttribute("id", this.ClientID );
            writer.WriteAttribute("name", this.ClientID );
           writer.WriteAttribute("value", this.Text, true);
          writer.Write("/> ");

            base.Render(writer);
        }

       //Text change event handler
        protected virtual void OnTextChanged(EventArgs e)
        {
            EventHandler handler = (EventHandler)base.Events[EventTextChanged];
            if (handler != null)
            {
                handler(this, e);
            }
        }

              [Localizable(true), Bindable(true, BindingDirection.TwoWay), PersistenceMode(PersistenceMode.EncodedInnerDefaultProperty), DefaultValue("")]
        public virtual string Text
        {
            get
            {
                string str = (string)this.ViewState["Text"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["Text"] = value;
            }
        }

   }