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 ?
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With