ASP.NET Repeater中的ImageButton不会触发OnClick事件处理程序

我在转发器控件中有一个ImageButton。 我已将一个eventhandler附加到ImageButton的OnClick事件。 但是,当我单击ImageButton时,事件不会被触发。 如果我错过了什么,请告诉我。 谢谢

我已经附加了aspx页面和codebehind文件

       .add-tag-color-required { color:Red; } .add-tag-float-right { float:right; }   function GetRadWindow() { var oWindow = null; if (window.radWindow) oWindow = window.RadWindow; //Will work in Moz in all cases, including classic dialog else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well) return oWindow; } function Cancel() { // clean save search fields document.forms[0].reset(); //get a reference to the current RadWindow var oWindow = GetRadWindow(); oWindow.close(); }    

 Enter tags seperated by commas.


<asp:Label ID="labelTag" runat="server" Text="">  

文件背后的代码如下。

 using System; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace IV.Web.Searchv2UI.AddTag { public partial class AddTag : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { List tags = new List(); tags.Add("semiconductor"); tags.Add("electronics"); tags.Add("us"); ViewState["Tags"] = tags; repeaterTag.DataSource = tags; repeaterTag.DataBind(); } } protected void buttonAdd_Click(object sender, EventArgs e) { List tags = (List)ViewState["Tags"]; string[] newTags = radTextBoxTags.Text.Split(','); if (newTags.Length > 0) { foreach(string tag in newTags) { if (!tags.Contains(tag)) { tags.Add(tag); } } } ViewState["Tags"] = tags; repeaterTag.DataSource = tags; repeaterTag.DataBind(); radTextBoxTags.Text = string.Empty; } protected void imageButtonRemove_Click(object sender, EventArgs e) { List tags = (List)ViewState["Tags"]; ImageButton button = (ImageButton)sender; Panel panel = (Panel)button.Parent; string tag = ((Label)(panel.Controls[1])).Text; tags.Remove(tag); ViewState["Tags"] = tags; repeaterTag.DataSource = tags; repeaterTag.DataBind(); } } } 

在转发器控件内部,按钮的行为与外出时的行为不同。

您需要设置按钮的“ CommandName ”属性,并在Repeater.ItemCommand事件中检查该命令名称并在那里执行您的逻辑。

我有同样的问题,并通过使用av asp:Linkbutton与“OnCommand”事件解决它。 我的标记和代码背后发布在下面。

标记:

   

代码背后:

  protected void lbRemove_Command(object sender, CommandEventArgs e) { switch (e.CommandName) { case "Remove": Recipients.Remove(e.CommandArgument.ToString()); rptRecipients.DataSource = Recipients; rptRecipients.DataBind(); break; } }