简体   繁体   English

从转发器内的用户控件引发事件

[英]Raise event from user control inside repeater

I have a user control that raise an event and I want to catch in other place. 我有一个引发事件的用户控件,我想在其他地方捕捉。

In aspx I have; 在aspx中,我有;

<asp:Repeater runat="server" ID="rptMarcas" OnItemDataBound="rptMarcas_OnItemDataBound">
    <ItemTemplate>
         <uc1:FabricanteArbol runat="server" ID="treeMarca"/>
    </ItemTemplate>
</asp:Repeater>

In aspx.cs 在aspx.cs中

protected void rptMarcas_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        Albero_dll.FABRICANTES fab = (Albero_dll.FABRICANTES)e.Item.DataItem;

        App_Componentes_FabricanteArbol tree = (App_Componentes_FabricanteArbol)e.Item.FindControl("treeMarca");
        tree.cargar(fab);
        tree.OnSelectedNodeClicked += new EventHandler(OnSelectedNodeClicked);
    }
}

In the user control; 在用户控件中;

public event EventHandler OnSelectedNodeClicked;
if (OnSelectedNodeClicked != null)
{
    CatalogoChangedEventArgs eCat = new CatalogoChangedEventArgs(e, SesionManager.posCatalogo, irPagina);
    OnSelectedNodeClicked(this, eCat);
}

But always OnSelectedNodeClicked is null. 但始终OnSelectedNodeClicked为null。

Can anyone help? 有人可以帮忙吗?

I see the issue, though i need you to fix few things or tell me exact context. 我看到了这个问题,尽管我需要您修复一些问题或告诉我确切的上下文。

Albero_dll.FABRICANTES fab = (Albero_dll.FABRICANTES)e.Item.DataItem;

e.item.dataitem will be the instance of your usercontrol so Albero_dll.FABRICANTES should be replaced by your user control name. e.item.dataitem将是您的用户控件的实例,因此Albero_dll.FABRICANTES应该替换为您的用户控件名称。

App_Componentes_FabricanteArbol tree = (App_Componentes_FabricanteArbol)e.Item.FindControl("treeMarca"); App_Componentes_FabricanteArbol树=(App_Componentes_FabricanteArbol)e.Item.FindControl(“ treeMarca”); is wrong and will not work 是错误的,将无法正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM