按钮 OnItemCommand 未在内部触发 asp:Repeater
button OnItemCommand not firing inside asp:Repeater
我有一个 Web 表单项目,其中包含以下按钮 asp:Repeater
<asp:Repeater ID="rptBookingSlots" OnItemCommand="BookingSlotOnItemCommand" runat="server">
<ItemTemplate>
<tr>
<td>
<asp:Button ID="Button3" CssClass="Delete" CommandName="delete" CommandArgument="<%# (Container.DataItem as RemoveGroup).Id %>" runat="server" Text="Delete" OnClientClick="return confirm('Are you sure you want to permanently delete this record);" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
但是当我 select 通过前端按钮时,它永远不会点击我在后面的代码中指定的方法
protected void BookingSlotOnItemCommand(object source, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "delete": //do work to delete record
}
}
我有一个 page_preRender 方法,它总是在 post 包
protected void Page_PreRender(object sender, EventArgs e)
{
if (IsPostBack && !_dataBound)
{
BindAllData();
}
}
谁能解释为什么当我附加到进程时我的 onItemCommand 方法不会被命中,我无法删除记录?
谢谢
我这样做的方法是在 page_load 而不是 pre_render 中加载数据。
我已经测试过了,按钮命令已进入
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
var myList = new List<string> {"foo", "bar"};
rptBookingSlots.DataSource = myList;
rptBookingSlots.DataBind();
}
}
我有一个 Web 表单项目,其中包含以下按钮 asp:Repeater
<asp:Repeater ID="rptBookingSlots" OnItemCommand="BookingSlotOnItemCommand" runat="server">
<ItemTemplate>
<tr>
<td>
<asp:Button ID="Button3" CssClass="Delete" CommandName="delete" CommandArgument="<%# (Container.DataItem as RemoveGroup).Id %>" runat="server" Text="Delete" OnClientClick="return confirm('Are you sure you want to permanently delete this record);" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
但是当我 select 通过前端按钮时,它永远不会点击我在后面的代码中指定的方法
protected void BookingSlotOnItemCommand(object source, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "delete": //do work to delete record
}
}
我有一个 page_preRender 方法,它总是在 post 包
protected void Page_PreRender(object sender, EventArgs e)
{
if (IsPostBack && !_dataBound)
{
BindAllData();
}
}
谁能解释为什么当我附加到进程时我的 onItemCommand 方法不会被命中,我无法删除记录?
谢谢
我这样做的方法是在 page_load 而不是 pre_render 中加载数据。
我已经测试过了,按钮命令已进入
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
var myList = new List<string> {"foo", "bar"};
rptBookingSlots.DataSource = myList;
rptBookingSlots.DataBind();
}
}