I have two nested repeaters. In the nested footer, I have a text box and file upload controls. I was able to get the file upload instance without any problems, but the text field instance is null, although both of them are placed in the footer.
Here is the aspx part representing the footer of the internal 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 am 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 I start the page, I get this error,
Object reference not set to an instance of an object
What is caused by this line:
String postText = commentTextBox.Text.ToString();
I tried to remove the text code and only get the file to download, and it worked very well. The problem is accessing the text box.
: onclick . , , , ItemDataBound , Adrian Iftode, ItemCreated. onclick , , , . , .
:
TextBox commentTextBox;
FileUpload upFile;
Repeater childRepeater;
String postText;
:
protected void commentsRepeater_ItemCreated(object sender, RepeaterItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Footer))
{
childRepeater = (Repeater)sender;
commentTextBox = (TextBox)(e.Item.FindControl("comment_txt"));
postText = commentTextBox.Text.ToString();
upFile = (FileUpload)e.Item.FindControl("uploadImageBtn");
}
}
onclick:
protected void submitComment(object sender, EventArgs e)
{
Boolean insert = true;
if (upFile.HasFile || !String.IsNullOrEmpty(postText))
{
}
if , upFile , postText .
- , ?
.