在asp.net中为Web用户控件添加属性和事件(4) } private void ButtonLogOut_Click(object sender, System.EventArgs e) { //注销代码省略 OnLogInOutClick(this,new LogInOutEventArgs(LogInClickType.LongOut,true)); } //验证函数 private bool CustomValidate(string userName,string password) { //验证代码省略,假设通过 return true; } }}另外一个文件定义了枚举和参数类:using System;namespace ZZ{ public class LogInOutEventArgs : EventArgs { private LogInClickType type; private bool result; public LogInOutEventArgs(LogInClickType type,bool result):base() { this.type = type; this.result = result; } public LogInClickType Type { get{return this.type;} } //操作结果, public bool Result { get{return this.result;} } } //操作类型 public enum LogInClickType : int { LongIn, LongOut } //定义语言 public enum Language { Chinese, English }}接下去看看在aspx页面里面使用。新建一个Default.aspx页面,拖一个LogInOutControl用户控件到上面。<%@ Register TagPrefix="UC1" TagName="LogInOutControl" Src="LogInOutControl.ascx" %><%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false" Inherits="ZZ.Default" %><%@ Import Namespace="ZZ" %><HTML> <HEAD> <title>WebForm1</title> </HEAD> <body> <form id="Form1" method="post" runat="server"> <FONT face="宋体"> <uc1:LogInOutControl id="LogInOutControl1" runat="server"> </uc1:LogInOutControl> <asp:Label id="LabelMsg" runat="server"></asp:Label>