您的位置:首页 > 其它

WebUserControl简单事件定义

2008-07-10 09:50 316 查看
使用WebUserControl来创建控件的时候,事件的定义方法:

控件:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SuperControl.ascx.cs" Inherits="SuperControl" %>

<div>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

</div>

<div>

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnTextChanged="DropDownList1_TextChanged">

<asp:ListItem>1</asp:ListItem>

<asp:ListItem>2</asp:ListItem>

<asp:ListItem>3</asp:ListItem>

<asp:ListItem>4</asp:ListItem>

</asp:DropDownList>

</div>

后台:

public partial class SuperControl : System.Web.UI.UserControl

{

public event EventHandler TextChanged;//事件委托

protected void DropDownList1_TextChanged(object sender, EventArgs e)

{

if (TextChanged != null)

{

TextChanged(this, e);

}

}

}

在页面中的使用方法:

<SuperControl:SupperControl ID="myControl" runat="server" OnTextChanged="myControl_OnTextChanged"/>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐