[英]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.