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 + "\" />");
          }
       }
    }
  • 相关阅读:
    让你爱不释手的图片浮动效果
    Polymer API开发指南 (二)(翻译)
    基于HTML5的拓扑图编辑器(2)
    kbengine开源分布式游戏服务端引擎
    Qunee for HTML5 v1.6新版本发布
    [转载] Link prefetch
    小白学phoneGap《构建跨平台APP:phoneGap移动应用实战》连载三(通过实例来体验生命周期)
    云集,让 web app 像 native app 那样运行(雄起吧,Web 开发者)
    Android设置ToolBar的title文字居中显示
    Task 'assembleXXXDebug' not found in project ':app'.的解决方法
  • 原文地址:https://www.cnblogs.com/shihao/p/2498657.html
Copyright © 2011-2022 走看看