首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

Web用户控件事件无法触发的有关问题

2013-02-06 
Web用户控件事件无法触发的问题各位大哥,小弟请教一个Web用户控件事件无法触发的问题,相关内容如下所示。控

Web用户控件事件无法触发的问题
各位大哥,小弟请教一个Web用户控件事件无法触发的问题,相关内容如下所示。

控件CheckBoxCell.ascx的内容如下:
<%@ Control ClassName="CheckBoxCell" Language="C#" AutoEventWireup="true" CodeFile="CheckBoxCell.ascx.cs" Inherits="admin_CheckBoxCell_CheckBoxCell" %>
<asp:CheckBox ID="chk" runat="server" AutoPostBack="True" 
    oncheckedchanged="chk_CheckedChanged" />
<asp:LinkButton ID="lbt" runat="server"></asp:LinkButton>



控件CheckBoxCell.ascx.cs的内容如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_CheckBoxCell_CheckBoxCell : System.Web.UI.UserControl
{
    //public delegate void CheckChangedHandler(object sender, EventArgs e);

    protected void Page_Load(object sender, EventArgs e)
    {
     
    }
    public  event EventHandler CheckedChanged;
    public CssStyleCollection Style
    {

        get
        {
            return this.lbt.Style;
        }

    }
    public Unit Height
    {
        set
        {
            this.lbt.Height = value;
        }
        get
        {
            return this.lbt.Height;
        }

    }

    protected void chk_CheckedChanged(object sender, EventArgs e)
    {
        CheckedChanged(sender, e);
    }
}



在一个使用该控件的aspx.cs文件中:

CheckBoxCell la = (CheckBoxCell)LoadControl("~/admin/CheckBoxCell/CheckBoxCell.ascx");
la.CheckedChanged += new EventHandler(la_CheckedChanged);


    protected void la_CheckedChanged(object sender, EventArgs e)
    {
        //throw new NotImplementedException();
        this.lstSelected.Items.Add("aaaaaaaaaaa");
    }

la_CheckedChanged()函数根本不执行,郁闷呀。

[解决办法]
la.CheckedChanged += new EventHandler(la_CheckedChanged);写在什么地方了,确认是否执行
[解决办法]
如果我没猜错的话楼主是想使用委托与事件吧,这有

热点排行