[英]How to fire event of textbox with OnItemCommand of a repeater , without using LinkButton?
我有一个内部的文本框的中继器,我想,当我从一个文本框移动到另一个文本框,与触发事件OnItemCommand
中继器。
<asp:Repeater ID="RptrPeople" runat="server" OnItemDataBound="RptrPeople_ItemDataBound" OnItemCommand="RptrPeople_ItemCommand">
<ItemTemplate>
<asp:HiddenField ID="hf" runat="server" Value="<%# Eval(this.ValuedPerson) %>" />
<asp:TextBox ID="txtDescription" runat="server" IsRequired="false" Visible="true" AutoPostBack="true" />
</ItemTemplate>
</asp:Repeater>
我试图使用文本框的OnTextChanged
,但我无法获得以这种方式触发事件的项目。
在我从一个文本框移动后,使用OnItemCommand
(例如,我在Textbox #1
输入123
,然后移动到Textbox #2
...然后,任何人都可以建议获得触发事件的项目的好方法)我想触发处理具有123
值的文本框的事件)?
谢谢
我试图使用文本框的OnTextChanged,但我无法获得以这种方式触发事件的项目。
sender
参数始终是触发事件的控件:
protected void txtDescription_TextChanged(Object sender, EventArgs e)
{
TextBox txtDescription = (TextBox) sender;
}
所以你应该使用它而不是OnItemCommand
因为sender
是转发器。
如果您还需要获取HiddenField
的引用,请使用以下代码:
protected void txtDescription_TextChanged(Object sender, EventArgs e)
{
TextBox txtDescription = (TextBox) sender;
var item = (RepeaterItem) txtDescription.NamingContainer;
HiddenField hf = (HiddenField) item.FindControl("hf");
}
RepeaterItem
中任何控件的NamingContainer
始终是RepeaterItem
。 顺便说一句,这与其他web-dataatabound控件(如GridView
或DataList
的工作方式类似。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.