zoukankan      html  css  js  c++  java
  • asp.net开发自定义控件

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

    namespace Custom
    {
     /// <summary>
     /// WebCustomControl1 的摘要说明。
     /// </summary>
     [DefaultProperty("Text"),
      ToolboxData("<{0}:Rendered runat=server></{0}:Rendered>")]
     public class Rendered : Control, IPostBackDataHandler, IPostBackEventHandler
     {
      
      private String text1;
      private String text2;
      private String text = "点击提交按钮看是否匹配.";
      private int number = 100;
         

      private int Sum
      {
       get
       {        
        return Int32.Parse(text1) +
         Int32.Parse(text2);
       }  
      }
         
      public int Number
      {
       get
       {
        return number;
       }
       set
       {
        number = value;
       }
      }
         
         
      public String Text
      {
       get
       {
        return text;
       }
       set
       {  
        text = value;
       }        
      }
         
      public event CheckEventHandler Check;
         
      protected virtual void OnCheck(CheckEventArgs ce)
      {
       if (Check != null)
       {
        Check(this,ce);
       }
      }
         
      public virtual bool LoadPostData(string postDataKey,
       NameValueCollection values)
      {
       text1 = values[UniqueID + "t1"];
       text2 = values[UniqueID+ "t2"];
       Page.RegisterRequiresRaiseEvent(this);
       return false;
      }
         
      public virtual void RaisePostDataChangedEvent()
      {
      }
         
      public void RaisePostBackEvent(string eventArgument)
      {
            
       OnCheck(new CheckEventArgs(Sum - Number));
      }
         
         
      protected override void Render(HtmlTextWriter output)
      {
       output.Write ("<h3>第一个数字 : ");
       output.Write("<INPUT type= text name = " + this.UniqueID + "t1" +
        " value = '0' >");
       output.Write("</h3><br>");  
       output.Write ("<br><h3>第二个数字: ");
       output.Write("<INPUT type= text name = " + this.UniqueID + "t2" +
        " value =  '0' >");
       output.Write("</h3><br>");  
       output.Write("<br><br><input type= submit name = " +
        this.UniqueID + " value= '提交'>");
       output.Write("<br><br><span style='height:50px;500px;'>"
        + Text + "</span>");
      }
     } 
     public class CheckEventArgs : EventArgs
     {
      private bool match = false;
               
      public CheckEventArgs (int difference)
      {
       if (difference == 0)
       {
        match = true;
       }
      }
      public bool Match
      {
       get
       {
        return match;
       }
      }
     }
         
     public delegate void CheckEventHandler(object sender, CheckEventArgs ce);

    }

  • 相关阅读:
    一个意外错误使你无法删除该文件,文件或目录损坏且无法读取(转)
    测验3: 基本数据类型 (第3周)-程序题
    Oracle深入学习
    自动化测试
    时尚随感
    SQL-使用事务删除重复记录行
    HDU1878欧拉回路
    简单的完全背包HDU1114
    简单的背包变形HDU1203,HDU2955
    简单的背包问题(入门)HDU2602 HDU2546 HDU1864
  • 原文地址:https://www.cnblogs.com/zhuawang/p/793625.html
Copyright © 2011-2022 走看看