⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 raiseeventcom.cs

📁 这是《ASP.NET编程实作教程》一书中的源文件 如果有此书的朋友不防下载过来参考
💻 CS
字号:
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace myControl {

    public class RaiseEventCom : Control, INamingContainer {

        public event EventHandler Change;
        
        protected void OnChange(EventArgs e) {
              Change(this, e);
        }
 
        //属性userID,取值时返回ID输入框的值
        public string userID {
           get {
               this.EnsureChildControls();
               return ((TextBox)Controls[1]).Text;
           }
        }
        
        //属性pwd,取值时返回password输入框的值
        public string pwd {
           get {
               this.EnsureChildControls();
               return ((TextBox)Controls[3]).Text;
           }
        }

        //重载CreateChildControls方法,在复合控件中添加控件
        protected override void CreateChildControls() {
        	
            //添加LiteralControl控件
            this.Controls.Add(new LiteralControl("用户:"));

            //添加输入框控件
            TextBox box = new TextBox();
            this.Controls.Add(box);
            box.TextChanged += new EventHandler(this.TextBox_Change);
            this.Controls.Add(new LiteralControl("<p>密码:"));
            
            //添加输入框控件
            box = new TextBox();
            box.TextMode=(TextBoxMode.Password);
            this.Controls.Add(box); 
            
            
            this.Controls.Add(new LiteralControl("<p>"));
            //添加提交按钮
            Button submitButton = new Button();
            submitButton.Text = "提交";
            this.Controls.Add(submitButton);
   
            //添加还原按钮
            Button resetButton = new Button();
            resetButton.Text = "还原";
            //绑定代表元
            resetButton.Click += new EventHandler(this.resetBtn_Click);
            this.Controls.Add(resetButton);

	}

        //还原按钮的事件处理函数
        private void resetBtn_Click(Object sender, EventArgs e) {
           ((TextBox)Controls[1]).Text="";
           ((TextBox)Controls[3]).Text="";
        }
        
        private void TextBox_Change(Object sender, EventArgs e) {
           OnChange(EventArgs.Empty);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -