• 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);

    }

  • 相关阅读:
    hdu Can you solve this equation
    hdu cup
    hdu Line belt
    三分搜索法
    hdu Strange fuction
    HDU 1175 连连看
    loadView、viewDidLoad及viewDidUnload的关系
    iOS图片拉伸技巧
    iOS完整学习路线图
    Core Data入门
  • 原文地址:https://www.cnblogs.com/zhuawang/p/793625.html
Copyright © 2020-2023  润新知