Reputation: 41
I have this source code:
<div id = "AddComment">
<asp:TextBox ID="txtComment" runat="server" TextMode="MultiLine" Height="20"></asp:TextBox>
<asp:Button ID="btnComment" CommandName="btnComment_click" runat="server" Text="Comment" />
</div>
and it's inside an item template tag for an ASP Repeater ... what i want to do is making c# code for some events for these two controls .. the text box and the button ... how can i reach these controls from the c # code ?
Upvotes: 4
Views: 10702
Reputation: 63956
You need to hook to the OnItemDataBound
<asp:Repeater OnItemDataBound="RepeaterItemEventHandler" ... />
Now, on code behind....
void RepeaterItemEventHandler(Object Sender, RepeaterItemEventArgs e) {
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
TextBox currentTextBox = (TextBox)e.Item.FindControl("txtComment");
//do something cool
}
}
Upvotes: 9