asp.netrepeatereventhandler

Event in repeater that is not triggered


I have an ASPX page and two user controls. Both of them contain a repeater. The ASPX page has a user control, and this user control in turn has another user control inside a repeater. When I click on a row in usrMedlemRow.rptMedlemmar, the showMedlemClick event should be triggered. However, it doesn't seem to be triggered, or usrMedlemslista is not catching it. What did I do wrong? Code on ASPX page:

<div class="row">
     <div class="col-9"><usr:Medlemslista runat="server" ID="usrMedlemsLista" /></div>
     <div class="col-3" style="border: 1px solid darkgray; background-color: white; padding: 0px; font-size: 12px; min-height: 700px;">
         <usr:MedlemsData runat="server" ID="usrMedlemsdata" Visible="false" />
     </div>
 </div>

Code on Usercontrol MedlemsLista (usrMedlemsLista):

  <asp:Repeater runat="server" ID="rptFastigheter">
       <HeaderTemplate />
        <ItemTemplate>
            <asp:Label runat="server" ID="lblFastighet" Text='<%#DataBinder.Eval(Container.DataItem, "Fastighetsbeteckning")%>' Visible="false" />                <usr:MedlemsRow runat="server" ID="usrMedlemsRow" />
        </ItemTemplate>
        <FooterTemplate />
    </asp:Repeater>

Codebehind:

    Public Event showMedlemClick2 As EventHandler
    Protected Sub rptFastigheter_ItemDataBound(S As Object, e As RepeaterItemEventArgs) Handles rptFastigheter.ItemDataBound
        If e.Item.ItemType = ListItemType.Item Then
            Dim control As MedlemRow = DirectCast(e.Item.FindControl("usrMedlemsRow"), MedlemRow)
            AddHandler control.showMedlemClick, AddressOf showMedlem2
        End If
    End Sub
    Protected Sub showMedlem2(s As Object, e As CommandEventArgs)
        Dim _eventCommands As New CommandEventArgs("MedlemsID", e.CommandArgument)
        RaiseEvent showMedlemClick2(Me, _eventCommands)
    End Sub

Code on Usercontrol MedlemRow:

    <asp:Repeater runat="server" ID="rptMedlemmar">
        <HeaderTemplate><div class="row"></HeaderTemplate>
        <ItemTemplate>
            <div class="col-1"><asp:LinkButton runat="server" ID="lnkNr" Text='<%#DataBinder.Eval(Container.DataItem, "Nr")%>' CommandArgument='<%#DataBinder.Eval(Container.DataItem, "MedlemsID")%>' OnCommand="showMedlem" /></div>
            <div class="col-2"><asp:LinkButton runat="server" ID="LinkButton1" Text='<%#DataBinder.Eval(Container.DataItem, "Fastighetsbeteckning")%>' CommandArgument='<%#DataBinder.Eval(Container.DataItem, "MedlemsID")%>' OnCommand="showMedlem" /></div>
            <div class="col-3"><asp:LinkButton runat="server" ID="LinkButton2" Text='<%#DataBinder.Eval(Container.DataItem, "Namn")%>' CommandArgument='<%#DataBinder.Eval(Container.DataItem, "MedlemsID")%>' OnCommand="showMedlem" /></div>
            <div class="col-2"><asp:LinkButton runat="server" ID="LinkButton3" Text='<%#fixMobil(DataBinder.Eval(Container.DataItem, "Mobil"))%>' CommandArgument='<%#DataBinder.Eval(Container.DataItem, "MedlemsID")%>' OnCommand="showMedlem" /></div>
            <div class="col-3"><asp:LinkButton runat="server" ID="LinkButton4" Text='<%#DataBinder.Eval(Container.DataItem, "Epost")%>' CommandArgument='<%#DataBinder.Eval(Container.DataItem, "MedlemsID")%>' OnCommand="showMedlem" /></div>
            <div class="col-1">&nbsp;</div>
        </ItemTemplate>
        <FooterTemplate></div></FooterTemplate>
    </asp:Repeater>

Codebehind:

    Public Event showMedlemClick As EventHandler
   Protected Sub showMedlem(s As Object, e As CommandEventArgs)
        Dim _eventCommands As New CommandEventArgs("MedlemsID", e.CommandArgument)
        RaiseEvent showMedlemClick(Me, _eventCommands)
    End Sub

Please help me, I'm really stuck.


Solution

  • Try adding

    runat="server"
    

    to your divs. Also, you might consider changing OnCommand to OnServerClick, but that's up to you to decide. See more here.