zoukankan      html  css  js  c++  java
  • Building ASP.NET Server ControlsCustomEventTextbox.cs

    // Title: Building ASP.NET Server Controls
    //
    // Chapter: 5 - Event-based Programming
    // File: CustomEventTextbox.cs
    // Written by: Dale Michalk and Rob Cameron
    //
    // Copyright ?2003, Apress L.P.

    using System;
    using System.Web;
    using System.Web.UI;
    using System.Collections.Specialized;
    using System.ComponentModel;

    namespace ControlsBookLib.Ch05
    {
       [ToolboxData("<{0}:CustomEventTextbox runat=server></{0}:CustomEventTextbox>"),
       DefaultProperty("Text")]
       public class CustomEventTextbox : Control, IPostBackDataHandler
       {
          private string oldText;

          public virtual string Text
          {
             get
             {
                object text = ViewState["Text"];
                if (text == null)
                   return string.Empty;
                else
                   return (string) text;
             }
             set
             {
                ViewState["Text"] = value;
             }
          }

          public bool LoadPostData(string postDataKey,
             NameValueCollection postCollection)
          {
             string postedValue = postCollection[postDataKey];
             if (!Text.Equals(postedValue))
             {
                oldText = Text;
                Text = postedValue;
                return true;
             }
             else
                return false;
          }

          public void RaisePostDataChangedEvent()
          {
             OnTextChanged(new TextChangedEventArgs(oldText, Text));
          }

          protected void OnTextChanged(TextChangedEventArgs tce)
          {
             if (TextChanged != null)
                TextChanged(this, tce);
          }
          public event TextChangedEventHandler TextChanged;

          override protected void Render(HtmlTextWriter writer)
          {
             base.Render(writer);
             Page.VerifyRenderingInServerForm(this);
             // write out the <INPUT type="text"> tag
             writer.Write("<INPUT type=\"text\" name=\"");
             writer.Write(this.UniqueID);
             writer.Write("\" value=\"" + this.Text + "\" />");
          }
       }
    }
  • 相关阅读:
    jquery事件学习笔记(转载)
    当sql报错代码,不允许对表操作的原因
    db2数据库创建一张表,并为该表加上主键递增的性能和中间表的创建的sql语句
    在Eclipse中导入dtd和xsd文件,使XML自动提示
    liunx系统环境下,爆出该错误"org.eclipse.wst.validation" has been removed解决办法
    linux 系统下配置tomcat,并给tomcat赋予最高操作权限,启动tomcat和关闭tomcat
    linux 系统下配置maven环境
    linux 系统下配置java环境变量
    hessian+spring集成应用
    Xshell添加ssh隧道SOCKS代理
  • 原文地址:https://www.cnblogs.com/shihao/p/2498657.html
Copyright © 2011-2022 走看看