[英]Submit TextBox From Within A Repeater
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: 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. CODEBEHIND - 这是应该在点击时执行的。 I replaced my SQL code with Response.Write:
我用Response.Write替换了我的SQL代码:
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. 更新:更改了一些设置,现在我遇到的唯一问题是输入客户端的文本没有传递给命令。
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">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.