I have two nested repeaters. In the nested one's footer I have text box and file upload controls. I was able to get an instance of the file upload without any problem, but the instance of the text box is null, though both are placed in the footer.

Here is the aspx part representing the footer of the inner repeater:

<FooterTemplate>
            <tr class="add_comment">
                <td>Add comment </td>

            </tr>
            <tr>
                <td>
                    <asp:TextBox runat="server" Columns="20" Rows="3" ID="comment_txt" TextMode="MultiLine" Width="60%" CssClass="new_comment" ViewStateMode="Inherit"></asp:TextBox>

                </td>

             </tr>

           <tr class="add_comment">
                <td>
                            <asp:FileUpload ID="uploadImageBtn" runat="server" Text="Add image" OnClick="uploadImage" CssClass="comment_buttons" />

                            <asp:Button ID="comment_btn" runat="server" OnClick="submitComment" Text="Comment" CssClass="comment_buttons" />
                </td>
       </tr>

         </table>
     </FooterTemplate>

This is the C# code where I'm trying to access the controls:

protected void commentsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Footer ))
            {
                Repeater childRepeater = (Repeater)sender;
                TextBox commentTextBox = (TextBox)e.Item.FindControl("comment_txt");
                String postText = commentTextBox.Text.ToString(); 
                FileUpload upFile = (FileUpload)e.Item.FindControl("uploadImageBtn");
            }
        }

When running the page I get this error,

Object reference not set to an instance of an object 

Which is caused by this line:

String postText = commentTextBox.Text.ToString(); 

I tried to remove the text box code and retrieve only the upload file and it worked very well. The problem is in accessing the text box.

Can anyone please help me, what is causing this error?

Thank you.

Related posts

Recent Viewed