zoukankan      html  css  js  c++  java
  • 理解button的Click事件和TextBox的TextChanged\DropDownList.SelectedIndexChanged的实现原理的区别

    using System;
    using System.Web.UI;
    using System.ComponentModel;
    namespace control
    {
     /// <summary>
     /// 理解button的Click事件和TextBox的TextChanged\DropDownList.SelectedIndexChanged的区别
     /// </summary>
     public class control1 : Control,IPostBackEventHandler,IPostBackDataHandler 
     {
      public control1()
      {
      }
      private string name;

      [BrowsableAttribute(true)]
      [DescriptionAttribute("姓名")]
      [DefaultValueAttribute("自定义名称")]
      [CategoryAttribute("aaa")]
      public virtual string PersonName
      {
       set
       {
        this.name=value;
       }
       get
       {
        return this.name;
       }
      }

      /// <summary>
      /// 老数据保存在ViewState中,如果禁用了ViewState则回传数据将失效
      /// </summary>
      public string Text
      {
       get
       {
        object text = ViewState["Text"];
        if (text == null)
         return string.Empty;
        else
         return (string)text;
       }
       set
       {
        ViewState["Text"] = value;
       }
      }


      

      protected override void Render(HtmlTextWriter writer)
      {
       writer.Write("<INPUT TYPE=submit name="+this.UniqueID+" Value='确定' /");   
       //writer.Write("<INPUT TYPE='text'   name="+this.UniqueID+" Value='"+this.Text+"' /");
       base.Render(writer);
      }

      #region 事件回传
    //  public delegate void EventHandler(Object sender, EventArgs e);
    //  public event EventHandler Click;
      public event EventHandler Click;//相当于上面两句
      protected virtual void OnMxhClick(System.EventArgs e)
      {
       if(Click!=null)
       {
        Click(this,e);
       }
      }
      public void RaisePostBackEvent(string eventArgument)
      {
       OnMxhClick(EventArgs.Empty);
      }
      #endregion


      #region 数据回传
      /// <summary>
      /// 判断是否调用RaisePostDataChangedEvent()
      /// </summary>
      /// <param name="postDataKey">传回来的新数据</param>
      /// <param name="postCollection"></param>
      /// <returns></returns>
      public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
      {
       string postData=postCollection[postDataKey];
       if(!Text.Equals(postData))
       {
        Text=postData;
        return true;//不同则自动调用RaisePostDataChangedEvent()函数
       }
       else
       {
        return false;
       }
      }

      public void RaisePostDataChangedEvent()
      {
       OnTextChanged(EventArgs.Empty);
      }

      public event EventHandler TextChanged;
      public void OnTextChanged(EventArgs e)
      {
       if(TextChanged!=null)
       {
        TextChanged(this,e);
       }
      }
      #endregion

     }
    }

  • 相关阅读:
    容器编排之rancher
    ActiveMQ安装配置
    Ansible Playbook
    AnsibleTower
    Ansible Configuration file
    jenkins报错jdk1.8/jre/lib/amd64/libawt_xawt.so
    Nexus安装配置
    maven 国内可用的中央仓库 阿里云
    jenkins Master stays offline if low disk space
    win版tesseract安装
  • 原文地址:https://www.cnblogs.com/kuailewangzi1212/p/751532.html
Copyright © 2011-2022 走看看