Reputation: 36652
I have a Repeater
structured something like this:
<asp:Repeater ID="rptListClaimTypes" runat="server">
<ItemTemplate>
<asp:FileUpload ID="fuContract" runat="server" />
<asp:LinkButton ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" CommandName='<%# Eval("ClaimTypeID")%>' />
</ItemTemplate>
</asp:Repeater>
I need to handle the file upload when btnUpload
is clicked. I can access the control that triggered the subroutine with sender
. How would I access fuContract
?
Protected Sub btnUpload_Click(sender As Object, e As EventArgs)
Dim ClaimTypeID As Integer = sender.CommandName
Dim fuContract As FileUpload = '??
End Sub
Upvotes: 0
Views: 512
Reputation: 9193
Using your current method of Event handling you would cast the sender as a LinkButton, cast the parent as a RepeaterItem, and then use FindControl to find the FileUpload Control:
Dim fuContract As FileUpload = CType(CType(sender, LinkButton).Parent.FindControl("fuContract"), FileUpload)
I prefer handling these types of Events using the Repeater's ItemCommand Event though:
Private Sub rptListClaimTypes_ItemCommand(source As Object, e As RepeaterCommandEventArgs) Handles rptListClaimTypes.ItemCommand
Dim fuContract As FileUpload = CType(e.Item.FindControl("fuContract"), FileUpload)
End Sub
Upvotes: 1