Reputation: 4107
I want to do something simple. I have a text box in a repeater Item that will allow people to add a note to the item. My code is not working, it doesn't seem like anything is happening at all.
ASPX:
<asp:Repeater ID="rptList" runat="server" ViewStateMode="Enabled">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="NoteTextBox" runat="server"></asp:TextBox>
<asp:Button ID="SubmitNote" runat="server" Text="Button" OnClick="lnkClient_Click" CommandName="AddNote" CommandArgument='<%# Eval("UID")%>'/>
<asp:Label ID="ShowNotes" runat="server" Text='<%# getNotes(Eval("UID").ToString())%>'></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
CODEBEHIND - This is what should be executed on click. I replaced my SQL code with Response.Write:
public void lnkClient_Click(object sender, EventArgs e)
{
Button btn = (Button)(sender);
string FID = btn.CommandArgument.ToString();
string note = ((TextBox)rptList.Items[0].FindControl("NoteTextBox")).Text;
Response.Write(FID + " " + note);
}
UPDATE: Changed some settings and now the only problem I am having is that the text entered client side is not passed to the command.
Upvotes: 0
Views: 1463
Reputation: 7059
Try this
protected void Repeater_OnItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("AddNote"))
{
string FID =e.CommandArgument.ToString();
TextBox txtNote=e.Item.FindControl("NoteTextBox") as TextBox;
string note=txtNote.Text;
Response.Write(FID + " " + note);
}
}
and in Mark up
<asp:Repeater ID="rptList" runat="server" OnItemCommand="Repeater_OnItemCommand" ViewStateMode="Enabled">
Upvotes: 2