星期五, 6月 25, 2010

[Asp.Net] 自訂使用者控制項事件

參考一下就會了喔,不過以下文章範例都是使用EventHander的委派事件處理函式。
ASP.NET自訂使用者控制項 
UserControl] 在使用者控制項中建立事件處理函式
看需求可自已重新定義有回傳值的委派與事件!!


//我的使用者控制項
public partial class user_control_MemberRoleList : System.Web.UI.UserControl
{
    private RoleType rt = RoleType.inside;

    public delegate void DeletedMemberRole(int roleID);//宣告delete角色委派
    public event DeletedMemberRole DeletedMemberRoleEvent;

    public delegate void AddedMemberRole(int newRoleID);//宣告add角色委派
    public event AddedMemberRole AddedMemberRoleEvent;


   protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnAddRole_Click(object sender, EventArgs e)
    {
             //dosomething
                        if (this.AddedMemberRoleEvent != null)
                            this.AddedMemberRoleEvent(Convert.ToInt32(newIndex));

    }
}


//使用使用者控制項的頁面
protected void Page_Load(object sender, EventArgs e)
{
        this.MemberRoleList1.DeletedMemberRoleEvent += new user_control_MemberRoleList.DeletedMemberRole(DeletedMemberRole);
        this.MemberRoleList1.AddedMemberRoleEvent += new user_control_MemberRoleList.AddedMemberRole(AddedMemberRole);

        this.MemberRoleList2.DeletedMemberRoleEvent += new user_control_MemberRoleList.DeletedMemberRole(DeletedMemberRole);
        this.MemberRoleList2.AddedMemberRoleEvent += new user_control_MemberRoleList.AddedMemberRole(AddedMemberRole);
        this.MemberRoleList2.SetRoleType = user_control_MemberRoleList.RoleType.outside;

}

 public void AddedMemberRole(int newRoleID)
 {
    //dosomething
 }

沒有留言:

張貼留言

留個話吧:)

其他你感興趣的文章

Related Posts with Thumbnails