[英]ItemCommand event doesn't fire with repeater control in master page
[英]ItemCommand event doesn't fire with the Repeater control
我正在建立一個網站,人們在離開購物車(並轉移到付款iframe)之前,可以從購物車列表中選擇要刪除的項目。 購物卡的結果在“轉發器”控件中列出。 轉發器中有一個按鈕,用於從數據庫中刪除一條記錄(使用LINQ to SQL來做到這一點。)
問題是,當我單擊按鈕時,ItemCommand事件不會觸發。 我嘗試了“ response.write(test)”,但仍然無法正常工作。 好像轉發器無法與命令交互。 它確實呈現結果。
如果在臨近截止日期之前您能為我提供幫助,並且在聯系你們之前,我已經耗盡了Internet上的所有資源,我將不勝感激!
這是代碼:
<asp:Repeater ID="RepeaterKoshnichka" runat="server" DataSourceID="LinqDataSource1">
<ItemTemplate>
<tr>
<td background="images/message-bar.gif">
<div class="message_head" style="float:left"><cite>Производ: <asp:Label ID="lblProizvod" CssClass="red_tx" Text='<%# Eval("Proizvod") %>' runat="server"></asp:Label> / Тип на Претплата: <asp:Label ID="lblPretplata" runat="server" Text='<%# Eval("Tip") %>' CssClass="red_tx"></asp:Label></cite></div>
<div class="message_head" style="float:right"><cite>Цена: <asp:Label ID="lblCena" CssClass="red_tx" Text='<%# Eval("Cena") %>' runat="server"></asp:Label>
<asp:Button ID="Button2" CssClass="main_tx" CommandName="Delete" CommandArgument='<%# Eval("NDetID") %>' runat="server"
Text="Отстрани" /></cite>
</div>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
protected void RepeaterKoshnichka_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
if (Request.Form[e.CommandArgument.ToString()] != null)
{
if (Page.User.Identity.IsAuthenticated)
{
var nar = new DataClasses1DataContext();
Guid detnar = new Guid(e.CommandArgument.ToString());
var query = from c in nar.Naracka_Dets
where c.NDetID == detnar
select c;
foreach (var c in query)
{
nar.Naracka_Dets.DeleteOnSubmit(c);
}
nar.SubmitChanges();
lblSuma.Text = ((Button)e.CommandSource).ToString();
}
}
}
}
非常感謝您的幫助!
您需要添加onitemcommand事件處理程序鏈接,即
OnItemCommand="RepeaterKoshnichka_ItemCommand"
<asp:Button UseSubmitBehavior =“ False” ... />
需要注意的一件事是,在綁定時,請確保僅在未回發(或處理完事件后)的情況下才進行綁定,否則會丟失該事件。
我遇到一個類似的問題,但沒有任何解決方案。 最終(在搜索了很長時間之后),我發現頁面上的文本字段沒有通過驗證,因此我只將CausesValidation="false"
添加到轉發器中的按鈕上,問題就解決了。
頁面上的其他控件是否發生了回發? 您的網頁上是否有任何JavaScript,例如“ javascript:void(0)”?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.