KJSR
KJSR

Reputation: 1757

Repeater Linkbutton Onclick not firing

I am having problem with the LinkButton onclick event not firing.

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?

Upvotes: 2

Views: 4981

Answers (3)

Drew Fleming
Drew Fleming

Reputation: 347

For me the fix was to set EnableViewState="true" the the control tag of my ascx file.

E.G.

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

And my LinkButton looks like this

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

Upvotes: 0

Mahmoude Elghandour
Mahmoude Elghandour

Reputation: 2931

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

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

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

Upvotes: 3

fubo
fubo

Reputation: 45947

The LinkButton within your DataControl triggers the Method rprOrders_ItemCommand

Set a breakpoint there. If you have multiple LinkButton then you can read CommandName="OrderDate" Codebehind: (e.CommandName)

For passing values CommandArgument should be used.

Upvotes: 4

Related Questions