Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > ItemCommand Not Fired View modes: 
User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 1/21/2013 12:51:28 PM
   
ItemCommand Not Fired
I've looked around and found this post and it hasn't helped a bit but cannot figure out why my ItemCommand isn't fired. I've got a pretty simple webpart as you can see below, on page load it displays a textbox and button. The user enters text and clicks the button and a search is performed. If there are results in the repeater, the ItemTemplate has a <asp:LinkButton> in it that should allow them to click it and fire the ItemCommand event. Lookup works great as usual, just not sure on the Repeater Events. Any ideas?

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SigSubs.ascx.cs" Inherits="CMSWebParts_MyWebParts_SigSubs" %>
<asp:Panel ID="pnlLookup" runat="server" DefaultButton="btnLookup">
<cms:LocalizedLabel ID="lblEmailOrCell" runat="server" />
<asp:TextBox ID="txtEmailOrCell" runat="server" /><br />
<cms:CMSButton ID="btnLookup" runat="server" CssClass="input-button" OnClick="btnLookup_Click" />
</asp:Panel>
<asp:Panel ID="pnlMessage" runat="server">
<cms:LocalizedLabel ID="lblMessage" runat="server" CssClass="errorLg" />
</asp:Panel>
<cms:CMSRepeater ID="rptItems" runat="server" OnItemCommand="rptItems_ItemCommand" />

public override void OnContentLoaded()
{
base.OnContentLoaded();
SetupControl();
}

/// <summary>
/// Initializes the control properties
/// </summary>
protected void SetupControl()
{
if (this.StopProcessing)
{
// Do nothing
}
else
{
lblMessage.Text = "";
// design properties
lblEmailOrCell.Text = LabelText;
btnLookup.Text = ButtonText;

// repeater properties
rptItems.AlternatingTransformationName = AlternatingTransformationName;
rptItems.TransformationName = TransformationName;
rptItems.HeaderTemplate = CMSDataProperties.LoadTransformation(this, HeaderTransformationName, true);
rptItems.FooterTemplate = CMSDataProperties.LoadTransformation(this, FooterTransformationName, true);
rptItems.SeparatorTemplate = CMSDataProperties.LoadTransformation(this, SeparatorTransformationName, true);
if (!String.IsNullOrEmpty(ZeroRowsText))
{
rptItems.ZeroRowsText = ZeroRowsText;
}
rptItems.HideControlForZeroRows = HideControlForZeroRows;

if (!RequestHelper.IsPostBack())
{
rptItems.ZeroRowsText = "";
}
}
}

/// <summary>
/// Reloads data
/// </summary>
public override void ReloadData()
{
base.ReloadData();
}

#endregion

#region "Events"
protected void btnLookup_Click(object sender, EventArgs e)
{
DoLookUp();
}

protected void rptItems_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
// do some work here
// then databind
DoLookUp();
}

#endregion

#region "Private methods"
private void DoLookUp()
{
// do some work here
rptItems.DataSource = ds;
rptItems.DataBind();
}

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 1/21/2013 1:36:31 PM
   
RE:ItemCommand Not Fired
Forgot to post my ItemTransformation code
<div class="unsubscribe">
<div>Subscribed via <%# Eval("SubscriptionType") %></div>
<asp:LinkButton ID="LinkButton1" runat="server" Text="Unsubscribe" CommandName="Unsubscribe" CommandArgument='<%# Eval("ListId") %>' />
</div>

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 1/30/2013 4:49:42 AM
   
RE:ItemCommand Not Fired
Hi,

could oyu please use the Basic repeater? The CMSRepeater's life cycle is affected by the additional things it has for the documents. I believe that basic repeater will solve this issue.

Best regards,
Juraj Ondrus

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 1/30/2013 8:50:53 AM
   
RE:ItemCommand Not Fired
Good to know that about the CMSRepeater. I did change it to the BasicRepeater although I still have the same results, the ItemCommand is not fired.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 2/1/2013 2:45:15 AM
   
RE:ItemCommand Not Fired
In this case it seems that the life cycle is not ensured correctly. You will need to use your cusotm web part insode the "User control" web part which is loading the control dynamically and ensures correct life cycle.

Best regards,
Juraj Ondrus

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 2/1/2013 10:19:17 AM
   
RE:ItemCommand Not Fired
So are you saying I will need to create a user control that does not inherit the CMSAbstractWebpart? If so, how do I expose the public properties I have in order for the user to set values of different items?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 2/4/2013 7:24:56 AM
   
RE:ItemCommand Not Fired
Hi,

basically you do not need to inherit from that class. you need to dynamically load the control - you can take inspiration in the User control web part.

Best regards,
Juraj Ondrus

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 2/1/2013 10:21:34 AM
   
RE:ItemCommand Not Fired
One other question, do you have a recommendation to do something different? Something that doesn't involve a repeater and an item command? What I have is a list of subscriptions and I place a linkbutton in the itemtemplate to unsubscribe.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 2/4/2013 7:26:00 AM
   
RE:ItemCommand Not Fired
Hi,

In the way you are doing it now the only thing you are using from our control are the transformations - you are loading the data on your own. So, you can also create a code that will display the data as you need to.

Best regards,
Juraj Ondrus

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 2/4/2013 8:37:06 AM
   
RE:ItemCommand Not Fired
Aside from the transformations being loaded, I have 7 other public properties that are being set by the user in the webpart properties. I don't mind setting the transformations in code but I still want to give the user the ability to set the other properties I have.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 2/5/2013 2:25:14 AM
   
RE:ItemCommand Not Fired
Hi,

As I mentioned previously - you will need, in this case, load the control dynamically on your own. you can take inspiration from the user control web part.

Best regards,
Juraj Ondrus

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 2/5/2013 7:31:41 AM
   
RE:ItemCommand Not Fired
Thanks! I removed my BasicRepeater from my markup and placed an instance in the code behind, then moved my creation of the BasicRepeater to the OnInit event and it worked like a charm!