简体   繁体   English

中继器链接按钮 Onclick 未触发

[英]Repeater Linkbutton Onclick not firing

I am having problem with the LinkButton onclick event not firing.我遇到了 LinkButton onclick 事件未触发的问题。

I have checked the following posts and taken the precaution of Postback but still joy我检查了以下帖子并采取了回发的预防措施,但仍然很高兴

repeater linkbutton not firing 中继器链接按钮未触发

Repeater's Item command event is not firing on linkbutton click 中继器的项目命令事件未在链接按钮单击时触发

Here is my Code so far到目前为止,这是我的代码

<asp:PlaceHolder runat="server" ID="phOrders">
<asp:Repeater ID="rprOrders" runat="server" OnItemCommand="rprOrders_ItemCommand">
  <HeaderTemplate>
    <table>
      <tr>
        <th>
          <asp:LinkButton ID="lnkOrderByDate" runat="server" Text="Date" CommandName="OrderDate" OnClick="lnkOrderByDate_Click"></asp:LinkButton></th>
        <th>
          <asp:LinkButton ID="lnkOrderByOrderNumber" runat="server" Text="Order Number"></asp:LinkButton></th>
        <th>
          <asp:LinkButton ID="lnkOrderByProductNumber" runat="server" Text="Product Number"></asp:LinkButton></th>
        <th>Product Description</th>
        <th>Size</th>
        <th>QTY</th>
        <th>Status</th>
      </tr>
  </HeaderTemplate>
  <ItemTemplate>
    <tr>
      <td><strong><%# Eval("OrderDate") %></strong></td>
      <td><%# Eval("OrderNumber") %></td>
      <td><%# Eval("SKUNumber") %></td>
      <td><%# Eval("OrderItemSKUName") %></td>
      <td><%# Eval("mtrx_Code2") %></td>
      <td><%# Eval("OrderItemUnitCount") %></td>
      <td><strong><%# Eval("OrderItemStatus") %></strong></td>
    </tr>
  </ItemTemplate>
  <FooterTemplate>
    </table>
  </FooterTemplate>
</asp:Repeater>
<div class="track-footer"></div>
</asp:PlaceHolder>

Code Behind代码背后

protected void SetupControl()
{
  if (this.StopProcessing)
  {
    // Do not process
  }
  else
  {
    if (CMSContext.ViewMode == ViewModeEnum.LiveSite)
    {      
      if(!Page.IsPostBack)
      {            
        PopulateProductClass();
        PopulateProduct();
        PopulateDefaultViewOrders();
      }
    }
  }
}

protected void lnkOrderByDate_Click(object sender, EventArgs e)
{
  //Do Something
}

Any suggestions?有什么建议么? I can't seem to figure it out?我好像想不通?

Even the OnItemCommand="rprOrders_ItemCommand" wont fire either?甚至OnItemCommand="rprOrders_ItemCommand"也不会触发?

The LinkButton within your DataControl triggers the Method rprOrders_ItemCommand DataControl中的LinkButton触发方法rprOrders_ItemCommand

Set a breakpoint there. 在此处设置一个断点。 If you have multiple LinkButton then you can read CommandName="OrderDate" Codebehind: (e.CommandName) 如果您有多个LinkButton则可以阅读CommandName="OrderDate" Codebehind: (e.CommandName)

For passing values CommandArgument should be used. 为了传递值,应使用CommandArgument

use some thing like this 用这样的东西

<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
    <asp:LinkButton ID="LinkButton1" runat="server" OnCommand="LinkButton1_Command" CommandName="MyUpdate" CommandArgument='<%# Eval("erid") %>'>LinkButton</asp:LinkButton>
</ItemTemplate>

.cs .cs

    protected void Repeater1_OnItemCommand(object source, RepeaterCommandEventArgs e)
 {
    if (e.CommandName.Equals("MyUpdate"))
    {
        // some code
    }

    if (e.CommandName.Equals("EditCategory"))
    {
        // some code
    }
}

For me the fix was to set EnableViewState="true" the the control tag of my ascx file.对我来说,解决方法是将EnableViewState="true"设置为我的 ascx 文件的控制标记。

EG例如

<%@ Control Language="C#" AutoEventWireup="True" CodeBehind="Settings.ascx.cs" Inherits="Foo.Bar.Settings" EnableViewState="true" %>

And my LinkButton looks like this我的 LinkButton 看起来像这样

<asp:LinkButton ID="btnRemoveMedia" 
                runat="server" 
                class="icon mdi-delete" 
                OnCommand="btnRemoveMedia_OnCommand" 
                CommandArgument="<%# ((Tuple<int, string>) Container.DataItem).Item1 %>" 
                CommandName="Delete" 
                UseSubmitBehavior="false" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM