Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't FindControl find the button in the footer of my repeater?

I am using an OnItemDataBound event to attempt to activate a disabled button in a repeater. Quite simply, if the event is triggered, I know there are items in the repeater and therefore want to enable the button. Where I am getting stuck is on casting the button in the function so I can enable it. The relevant part of the repeater code is below:

<asp:Repeater ID="RptEnterHours" runat="server" DataSourceID="SQL_EmployeeGetTimesheet" ClientIDMode="Predictable" OnItemDataBound="RptEnterHours_Bound">
     '.....Irrelevant code.....
     <FooterTemplate>
          <asp:Button Enabled="false" ID="SubmitTimesheets" Text="Submit All Timesheets" OnClick="processTimesheetEntry" runat="server" OnClientClick="checkValues();" />&nbsp;
     </FooterTemplate>
</asp:Repeater>

This is my code behind:

Sub RptEnterHours_Bound(Sender As Object, e As RepeaterItemEventArgs)

    'Exposes the Submit All Timesheets button if timesheets are available.
    If (e.Item.ItemType = ListItemType.Item) Or _
        (e.Item.ItemType = ListItemType.AlternatingItem) Then
        Dim sButton As Button = TryCast(Me.FindControl("SubmitTimesheets"), Button)
        sButton.Enabled = True
    End If

End Sub

This and all other attempts has yielded the dreaded "Object reference not set to an instance of an object" message. Can anyone tell me what I am doing wrong and why my code behind won't find the button?

like image 433
Ryan Avatar asked Oct 22 '22 12:10

Ryan


1 Answers

please try this i am sure it will help you.

    If e.Item.ItemType = ListItemType.Footer Then
        Dim btn as new button
        btn = CType(e.Item.FindControl("SubmitTimesheets"), Button)
        btn.enabled = true
    End If
like image 151
Ajay Thakkar Avatar answered Nov 15 '22 07:11

Ajay Thakkar